ExecuteNonQuery() public method

对SQLite数据库执行增删改操作,返回受影响的行数。
public ExecuteNonQuery ( string sql, SQLiteParameter parameters ) : int
sql string 要执行的增删改的SQL语句
parameters System.Data.SQLite.SQLiteParameter 执行增删改语句所需要的参数,参数必须以它们在SQL语句中的顺序为准
return int
示例#1
0
        public static void CreateTable()
        {
            string dbPath = "D:\\Demo.db3";

            //如果不存在改数据库文件,则创建该数据库文件
            if (!System.IO.File.Exists(dbPath))
            {
                SQLiteDBHelper.CreateDB("D:\\Demo.db3");
            }
            SQLiteDBHelper db  = new SQLiteDBHelper("D:\\Demo.db3");
            string         sql = "CREATE TABLE Test3(id integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,Name char(3),TypeName varchar(50),addDate datetime,UpdateTime Date,Time time,Comments blob)";

            db.ExecuteNonQuery(sql, null);
        }
示例#2
0
        public static void InsertData()
        {
            string         sql = "INSERT INTO Test3(Name,TypeName,addDate,UpdateTime,Time,Comments)values(@Name,@TypeName,@addDate,@UpdateTime,@Time,@Comments)";
            SQLiteDBHelper db  = new SQLiteDBHelper("D:\\Demo.db3");

            for (char c = 'A'; c <= 'Z'; c++)
            {
                for (int i = 0; i < 100; i++)
                {
                    SQLiteParameter[] parameters = new SQLiteParameter[] {
                        new SQLiteParameter("@Name", c + i.ToString()),
                        new SQLiteParameter("@TypeName", c.ToString()),
                        new SQLiteParameter("@addDate", DateTime.Now),
                        new SQLiteParameter("@UpdateTime", DateTime.Now.Date),
                        new SQLiteParameter("@Time", DateTime.Now.ToShortTimeString()),
                        new SQLiteParameter("@Comments", "Just a Test" + i)
                    };
                    db.ExecuteNonQuery(sql, parameters);
                }
            }
        }