当前位置: 首页>>代码示例>>C#>>正文


C# SqliteConnection.CreateCommand方法代码示例

本文整理汇总了C#中Community.CsharpSqlite.SQLiteClient.SqliteConnection.CreateCommand方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.CreateCommand方法的具体用法?C# SqliteConnection.CreateCommand怎么用?C# SqliteConnection.CreateCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Community.CsharpSqlite.SQLiteClient.SqliteConnection的用法示例。


在下文中一共展示了SqliteConnection.CreateCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CodeProjectDatabase

        public CodeProjectDatabase()
        {
            dbPath = "items.db3";

            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
            bool exists = isf.FileExists(dbPath);

            var connection = new SqliteConnection("data source=" + dbPath);
            connection.Open();
                
            if (!exists)
            {
                var commands = new[]{
					"CREATE TABLE [Member] (Key integer, Name ntext, ArticleCnt integer, BlogCnt integer, Reputation ntext, IsMe integer);"
				};
                foreach (var command in commands)
                {
                    using (var c = connection.CreateCommand())
                    {
                        c.CommandText = command;
                        c.ExecuteNonQuery();
                    }
                }
            }

        }
开发者ID:Trojka,项目名称:monoCPVanity,代码行数:26,代码来源:CodeProjectDatabase.WP7.cs

示例2: AddMember

		public bool AddMember(CodeProjectMember member)
		{
            var connection = new SqliteConnection("Data Source=" + dbPath);
            connection.Open();

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT [Key] FROM [Member] WHERE [Key]=" + member.Id;
                var r = command.ExecuteReader();
                if (r.HasRows)
                {
                    using (var uc = connection.CreateCommand())
                    {
                        uc.CommandText = "UPDATE [Member] SET " +
                            " [Name] = '" + member.Name + "'," +
                            " [ArticleCnt] = '" + member.ArticleCount + "'," +
                            " [BlogCnt] = '" + member.BlogCount + "'," +
                            " [Reputation] = '" + member.Reputation + "'," +
                            " WHERE [Key]=" + member.Id;
                        uc.ExecuteNonQuery();
                    }
                }
                else
                {
                    using (var ic = connection.CreateCommand())
                    {
                        ic.CommandText = "INSERT INTO [Member] ([Key], [Name], [ArticleCnt], [BlogCnt], [Reputation])"
                            + " VALUES(" + member.Id + ", '" + member.Name + "', '" + member.ArticleCount + "', '" + member.BlogCount + "', '" + member.Reputation + "')";
                        ic.ExecuteNonQuery();
                    }
                }
            }

            connection.Close();

            FileStorageService storage = new FileStorageService();
            if (member.Avatar != null)
            {
                storage.WriteBytes(member.Avatar, member.Id.ToString());
            }

            return true;
        }
开发者ID:Trojka,项目名称:monoCPVanity,代码行数:43,代码来源:CodeProjectDatabase.WP7.cs

示例3: CreateSchema

 /// <summary>
 /// Create schema of sync source table
 /// supports transaction
 /// </summary>
 /// <param name="con"></param>
 public static void CreateSchema(SqliteConnection con)
 {
     using (SqliteCommand cmd = con.CreateCommand())
     {
         cmd.CommandText = "CREATE TABLE IF NOT EXISTS " + Configuration.TBL_DATASOURCE_INFO +
                          " ( " + Configuration.COL_SOURCE_ABSOLUTE_PATH + " TEXT, " +
                          Configuration.COL_SOURCE_ID + " TEXT PRIMARY KEY)";
         cmd.ExecuteNonQuery();
     }
 }
开发者ID:nydehi,项目名称:onesync,代码行数:15,代码来源:SQLiteSyncSourceProvider.cs

示例4: ExecuteNonQuery

        public static int ExecuteNonQuery(string sql)
        {
            using (SqliteConnection connection = new SqliteConnection())
            {
                connection.ConnectionString = ConnectionString;
                System.Data.IDbCommand cmd = connection.CreateCommand();
                cmd.CommandText = sql;

                connection.Open();
                return cmd.ExecuteNonQuery();
            }
        }
开发者ID:pisceanfoot,项目名称:codeshare,代码行数:12,代码来源:SQLHepler.cs

示例5: Update

 /// <summary>
 /// Update details of sync source
 /// Pass SQLiteConnection object to make atomic action
 /// </summary>
 /// <param name="source"></param>
 /// <param name="con"></param>
 /// <returns></returns>
 public static bool Update(SyncSource source, SqliteConnection con )
 {
     using (SqliteCommand cmd = con.CreateCommand())
     {
         cmd.CommandText = "UPDATE " + Configuration.TBL_DATASOURCE_INFO +
                 " SET " + Configuration.COL_SOURCE_ABSOLUTE_PATH + " = @path WHERE "
                 + Configuration.COL_SOURCE_ID + " = @id";
         cmd.Parameters.Add(new SqliteParameter("@id", DbType.String) { Value = source.ID });
         cmd.Parameters.Add(new SqliteParameter("@path", DbType.String) { Value = source.Path });
         cmd.ExecuteNonQuery();
         return true;
     }
 }
开发者ID:nydehi,项目名称:onesync,代码行数:20,代码来源:SQLiteSyncSourceProvider.cs

示例6: Add

 /// <summary>
 /// This method takes in SQLiteConnection object as a parameter
 /// </summary>
 /// <param name="s"></param>
 /// <param name="con"></param>
 /// <returns></returns>
 public static bool Add(SyncSource s, SqliteConnection con)
 {
     using (SqliteCommand cmd = con.CreateCommand())
      {
          cmd.CommandText = "INSERT INTO " + Configuration.TBL_DATASOURCE_INFO +
                          "(" + Configuration.COL_SOURCE_ID + "," + Configuration.COL_SOURCE_ABSOLUTE_PATH +
                          ") VALUES (@id, @path)";
          cmd.Parameters.Add(new SqliteParameter("@id", DbType.String) { Value = s.ID });
          cmd.Parameters.Add(new SqliteParameter("@path", DbType.String) { Value = s.Path });
          cmd.ExecuteNonQuery();
      }
      return true;
 }
开发者ID:nydehi,项目名称:onesync,代码行数:19,代码来源:SQLiteSyncSourceProvider.cs

示例7: QueryVersion

 private int QueryVersion(SqliteConnection connection)
 {
     connection.Open();
     try
     {
         var tableExists = connection.CreateCommand();
         tableExists.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='version';";
         var versionNumber = connection.CreateCommand();
         versionNumber.CommandText = "SELECT num FROM version;";
         _log.Info("Query version table");
         using (var reader = tableExists.ExecuteReader())
         {
             if (!reader.HasRows)
             {
                 _log.Info("Database is empty");
                 return 0;
             }
         }
         _log.Info("Query version number");
         using (var reader = versionNumber.ExecuteReader())
         {
             reader.Read();
             var numb = (int) reader.GetValue(0);
             _log.Info(string.Format("Database version is {0}", numb));
             return numb;
         }
     }
     catch (Exception e)
     {
         _log.Fatal("Unexpected exception", e);
         throw;
     }
     finally
     {
         connection.Close();
     }
 }
开发者ID:Irdis,项目名称:VSTalk,代码行数:37,代码来源:ConnectionFactory.cs

示例8: ExecuteNonQuery

        /// <summary>
        /// Shortcut to ExecuteNonQuery with SqlStatement and object[] param values
        /// </summary>
        /// <param name="connectionString">SQLite Connection String</param>
        /// <param name="commandText">Sql Statement with embedded "@param" style parameters</param>
        /// <param name="paramList">object[] array of parameter values</param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string connectionString, string commandText, object[] paramList)
        {
            SqliteConnection cn = new SqliteConnection(connectionString);
            IDbCommand cmd = cn.CreateCommand();
            cmd.CommandText = commandText;
            if (paramList != null)
            {
                cmd.CommandText = string.Format(commandText, paramList);
            }

            if (cn.State == ConnectionState.Closed)
                cn.Open();
            int result = cmd.ExecuteNonQuery();
            cmd.Dispose();
            cn.Close();

            return result;
        }
开发者ID:pnhlong,项目名称:fingerPointSys,代码行数:25,代码来源:CsharpSQLiteHelper.cs

示例9: SqliteDataAdapter

 /// <summary>
 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class 
 /// with a SelectCommand and a SqliteConnection object.
 /// </summary>
 /// <param name="selectCommandText"></param>
 /// <param name="connection"></param>
 public SqliteDataAdapter(string selectCommandText, SqliteConnection connection)
 {
     DbCommand cmd = connection.CreateCommand();
     cmd.CommandText = selectCommandText;
     SelectCommand = cmd;
 }
开发者ID:R4P3NET,项目名称:TS3SRV-ASE,代码行数:12,代码来源:SqliteDataAdapter.cs

示例10: GetMember

		public CodeProjectMember GetMember(int memberId)
		{
            var connection = new SqliteConnection("Data Source=" + dbPath);
            connection.Open();

            CodeProjectMember member = new CodeProjectMember();
            member.Id = memberId;

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT [Key], [Name], [ArticleCnt], [BlogCnt], [Reputation], [IsMe] FROM [Member] WHERE [Key]=" + memberId;
                var r = command.ExecuteReader();
                while (r.Read())
                {
                    FillMemberFromDataReader(member, r);
                }
            }

            connection.Close();

            return member;
        }
开发者ID:Trojka,项目名称:monoCPVanity,代码行数:22,代码来源:CodeProjectDatabase.WP7.cs

示例11: GetMembers

        public List<CodeProjectMember> GetMembers()
		{
            List<CodeProjectMember> memberList = new List<CodeProjectMember>();

            var connection = new SqliteConnection("Data Source=" + dbPath);
            connection.Open();

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT [Key], [Name], [ArticleCnt], [BlogCnt], [Reputation], [IsMe] FROM [Member]";
                var r = command.ExecuteReader();
                while (r.Read())
                {
                    CodeProjectMember member = new CodeProjectMember();
                    FillMemberFromDataReader(member, r);
                    memberList.Add(member);
                }
            }

            connection.Close();

            return memberList;
        }
开发者ID:Trojka,项目名称:monoCPVanity,代码行数:23,代码来源:CodeProjectDatabase.WP7.cs

示例12: Issue_119

    public void Issue_119()
    {
      Console.WriteLine("Test Start.");

      Console.WriteLine("Create connection...");
      SqliteConnection con = new SqliteConnection();

      string dbFilename = @"=SqliteTest3=.db";
      string cs = string.Format("Version=3,uri=file:{0}", dbFilename);

      Console.WriteLine("Set connection String: {0}", cs);

      if (File.Exists(dbFilename))
        File.Delete(dbFilename);

      con.ConnectionString = cs;

      Console.WriteLine("Open database...");
      con.Open();

      Console.WriteLine("create command...");
      IDbCommand cmd = con.CreateCommand();

      Console.WriteLine("create table TEST_TABLE...");
      cmd.CommandText = "CREATE TABLE TEST_TABLE ( COLA INTEGER, COLB TEXT, COLC DATETIME )";
      cmd.ExecuteNonQuery();

      Console.WriteLine("insert row 1...");
      cmd.CommandText = "INSERT INTO TEST_TABLE ( COLA, COLB, COLC ) VALUES (123,'ABC','2008-12-31 18:19:20' )";
      cmd.ExecuteNonQuery();

      Console.WriteLine("insert row 2...");
      cmd.CommandText = "INSERT INTO TEST_TABLE ( COLA, COLB, COLC ) VALUES (124,'DEF', '2009-11-16 13:35:36' )";
      cmd.ExecuteNonQuery();

      Console.WriteLine("SELECT data from TEST_TABLE...");
      cmd.CommandText = "SELECT RowID, COLA, COLB, COLC FROM TEST_TABLE";
      IDataReader reader = cmd.ExecuteReader();
      int r = 0;
      Console.WriteLine("Read the data...");
      while (reader.Read())
      {
        Console.WriteLine("  Row: {0}", r);
        int rowid = reader.GetInt32(reader.GetOrdinal("RowID"));
        Console.WriteLine("    RowID: {0}", rowid);

        int i = reader.GetInt32(reader.GetOrdinal("COLA"));
        Console.WriteLine("    COLA: {0}", i);

        string s = reader.GetString(reader.GetOrdinal("COLB"));
        Console.WriteLine("    COLB: {0}", s);

        DateTime dt = reader.GetDateTime(reader.GetOrdinal("COLC"));
        Console.WriteLine("    COLB: {0}", dt.ToString("MM/dd/yyyy HH:mm:ss"));

        r++;
      }

      Console.WriteLine("Close and cleanup...");
      con.Close();
      con = null;

      Console.WriteLine("Test Done.");
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:64,代码来源:SQLiteClientTestDriver.cs

示例13: Test2

    public void Test2()
    {
      Console.WriteLine("Test2 Start.");

      Console.WriteLine("Create connection...");
      SqliteConnection con = new SqliteConnection();

      string dbFilename = @"SqliteTest3.db";
      string cs = string.Format("Version=3,uri=file:{0}", dbFilename);

      Console.WriteLine("Set connection String: {0}", cs);

      if (File.Exists(dbFilename))
        File.Delete(dbFilename);

      con.ConnectionString = cs;

      Console.WriteLine("Open database...");
      con.Open();

      Console.WriteLine("create command...");
      IDbCommand cmd = con.CreateCommand();

      Console.WriteLine("create table TEST_TABLE...");
      cmd.CommandText = "CREATE TABLE TBL ( ID NUMBER, NAME TEXT)";
      cmd.ExecuteNonQuery();

      Console.WriteLine("insert row 1...");
      cmd.CommandText = "INSERT INTO TBL ( ID, NAME ) VALUES (1, 'ONE' )";
      cmd.ExecuteNonQuery();

      Console.WriteLine("insert row 2...");
      cmd.CommandText = "INSERT INTO TBL ( ID, NAME ) VALUES (2, '中文' )";
      cmd.ExecuteNonQuery();

      //Console.WriteLine("commit...");
      //cmd.CommandText = "COMMIT";
      //cmd.ExecuteNonQuery();

      Console.WriteLine("SELECT data from TBL...");
      cmd.CommandText = "SELECT id,NAME FROM tbl WHERE name = '中文'";
      IDataReader reader = cmd.ExecuteReader();
      int r = 0;
      Console.WriteLine("Read the data...");
      while (reader.Read())
      {
        Console.WriteLine("  Row: {0}", r);
        int i = reader.GetInt32(reader.GetOrdinal("ID"));
        Console.WriteLine("    ID: {0}", i);

        string s = reader.GetString(reader.GetOrdinal("NAME"));
        Console.WriteLine("    NAME: {0} = {1}", s, s == "中文");
        r++;
      }
      Console.WriteLine("Rows retrieved: {0}", r);

      //alxwest: DataTable & SqliteDataAdapter currently unavailable for Silverlight
#if !SQLITE_SILVERLIGHT
      SqliteCommand command = new SqliteCommand("PRAGMA table_info('TEST_TABLE')", con);
      DataTable dataTable = new DataTable();
      SqliteDataAdapter dataAdapter = new SqliteDataAdapter();
      dataAdapter.SelectCommand = command;
      dataAdapter.Fill(dataTable);
      DisplayDataTable(dataTable, "Columns");
#endif

      Console.WriteLine("Close and cleanup...");
      con.Close();
      con = null;

      Console.WriteLine("Test1 Done.");
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:72,代码来源:SQLiteClientTestDriver.cs

示例14: SqliteDataAdapter

		/// <summary>
		/// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class 
		/// with a SelectCommand and a SqliteConnection object.
		/// </summary>
		/// <param name="selectCommandText"></param>
		/// <param name="connection"></param>
		public SqliteDataAdapter(string selectCommandText, SqliteConnection connection)
		{
#if NET_2_0
			DbCommand cmd;
#else
			IDbCommand cmd;
#endif

			cmd = connection.CreateCommand();
			cmd.CommandText = selectCommandText;
			SelectCommand = cmd;
		}
开发者ID:Belxjander,项目名称:Asuna,代码行数:18,代码来源:SqliteDataAdapter.cs

示例15: Test1

    public void Test1()
    {
      Console.WriteLine("Test1 Start.");

      Console.WriteLine("Create connection...");
      SqliteConnection con = new SqliteConnection();

      string dbFilename = @"SqliteTest3.db";
      string cs = string.Format("Version=3,uri=file:{0}", dbFilename);

      Console.WriteLine("Set connection String: {0}", cs);

      if (File.Exists(dbFilename))
        File.Delete(dbFilename);

      con.ConnectionString = cs;

      Console.WriteLine("Open database...");
      con.Open();

      Console.WriteLine("create command...");
      IDbCommand cmd = con.CreateCommand();

      Console.WriteLine("create table TEST_TABLE...");
      cmd.CommandText = "CREATE TABLE TEST_TABLE ( COLA INTEGER, COLB TEXT, COLC DATETIME )";
      cmd.ExecuteNonQuery();

      Console.WriteLine("insert row 1...");
      cmd.CommandText = "INSERT INTO TEST_TABLE ( COLA, COLB, COLC ) VALUES (123,'ABC','2008-12-31 18:19:20' )";
      cmd.ExecuteNonQuery();

      Console.WriteLine("insert row 2...");
      cmd.CommandText = "INSERT INTO TEST_TABLE ( COLA, COLB, COLC ) VALUES (124,'DEF', '2009-11-16 13:35:36' )";
      cmd.ExecuteNonQuery();

      //Console.WriteLine("commit...");
      //cmd.CommandText = "COMMIT";
      //cmd.ExecuteNonQuery();

      Console.WriteLine("SELECT data from TEST_TABLE...");
      cmd.CommandText = "SELECT COLA, COLB, COLC FROM TEST_TABLE";
      IDataReader reader = cmd.ExecuteReader();
      int r = 0;
      Console.WriteLine("Read the data...");
      while (reader.Read())
      {
        Console.WriteLine("  Row: {0}", r);
        int i = reader.GetInt32(reader.GetOrdinal("COLA"));
        Console.WriteLine("    COLA: {0}", i);

        string s = reader.GetString(reader.GetOrdinal("COLB"));
        Console.WriteLine("    COLB: {0}", s);

        DateTime dt = reader.GetDateTime(reader.GetOrdinal("COLC"));
        Console.WriteLine("    COLB: {0}", dt.ToString("MM/dd/yyyy HH:mm:ss"));

        r++;
      }
      Console.WriteLine("Rows retrieved: {0}", r);

      //alxwest: DataTable & SqliteDataAdapter currently unavailable for Silverlight
#if !SQLITE_SILVERLIGHT
      SqliteCommand command = new SqliteCommand("PRAGMA table_info('TEST_TABLE')", con);
      DataTable dataTable = new DataTable();
      SqliteDataAdapter dataAdapter = new SqliteDataAdapter();
      dataAdapter.SelectCommand = command;
      dataAdapter.Fill(dataTable);
      DisplayDataTable(dataTable, "Columns");
#endif

      Console.WriteLine("Close and cleanup...");
      con.Close();
      con = null;

      Console.WriteLine("Test1 Done.");
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:76,代码来源:SQLiteClientTestDriver.cs


注:本文中的Community.CsharpSqlite.SQLiteClient.SqliteConnection.CreateCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。