zoukankan      html  css  js  c++  java
  • C#操作sqlite数据库使用SQLiteParameter传递参数

    C# code

    public void AddIMG_ENTRY(img_entry model)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into IMG_ENTRY(");
                strSql.Append("IMG_ID,USER_ID,FOLDER_ID,STATU_ID,WORK_TIME,START_TIME,END_TIME,OUTPUT_STATUS,INPUT_DATA,INPUT_STATES,FORMAT_NAME)");
                strSql.Append(" values (");
                strSql.Append("@IMG_ID,@USER_ID,@FOLDER_ID,@STATU_ID,@WORK_TIME,@START_TIME,@END_TIME,@OUTPUT_STATUS,@INPUT_DATA,@INPUT_STATES,@FORMAT_NAME)");
                SQLiteParameter[] parameters = {
                        new SQLiteParameter("@IMG_ID", DbType.Int32,4),
                        new SQLiteParameter("@USER_ID", DbType.String),
                        new SQLiteParameter("@FOLDER_ID", DbType.Int32,4),
                        new SQLiteParameter("@STATU_ID", DbType.Int32,4),
                        new SQLiteParameter("@WORK_TIME", DbType.DateTime),
                        new SQLiteParameter("@START_TIME", DbType.DateTime),
                        new SQLiteParameter("@END_TIME", DbType.DateTime),
                        new SQLiteParameter("@OUTPUT_STATUS", DbType.Int32,4),
                        new SQLiteParameter("@INPUT_DATA", DbType.String),
                        new SQLiteParameter("@INPUT_STATES", DbType.Int32,4),
                        new SQLiteParameter("@FORMAT_NAME", DbType.String)};
                parameters[0].Value = model.IMG_ID;
                parameters[1].Value = model.USER_ID;
                parameters[2].Value = model.FOLDER_ID;
                parameters[3].Value = model.STATU_ID;
                parameters[4].Value = model.WORK_TIME;
                parameters[5].Value = model.START_TIME;
                parameters[6].Value = model.END_TIME;
                parameters[7].Value = model.OUTPUT_STATUS;
                parameters[8].Value = model.INPUT_DATA;
                parameters[9].Value = model.INPUT_STATES;
                parameters[10].Value = model.FORMAT_NAME;
    
                DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            }
    
     public static int ExecuteSql(string SQLString, string content)
            {
                using (SQLiteConnection connection = new SQLiteConnection(connectionString))
                {
                    SQLiteCommand cmd = new SQLiteCommand(SQLString, connection);
                    SQLiteParameter myParameter = new SQLiteParameter("@content", DbType.String);
                    myParameter.Value = content;
                    cmd.Parameters.Add(myParameter);
                    try
                    {
                        connection.Open();
                        int rows = cmd.ExecuteNonQuery();
                        return rows;
                    }
                    catch (System.Data.SQLite.SQLiteException E)
                    {
                        throw new Exception(E.Message);
                    }
                    finally
                    {
                        cmd.Dispose();
                        connection.Close();
                    }
                }
            }
  • 相关阅读:
    匿存函数,内存函数,递归函数,二分法查找
    内置函数
    生成器函数,推导式,生成器表达式
    函数名的应用,闭包,迭代器
    动态参数,作用域
    函数,返回值,参数
    文件操作
    什么是协程
    MYSQL允许远程访问
    phpstorm+xdebug搭建
  • 原文地址:https://www.cnblogs.com/tuyile006/p/3297017.html
Copyright © 2011-2022 走看看