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();
                    }
                }
            }
  • 相关阅读:
    如何快速打开Github
    vuecli4 如何创建带有vuerouter vuex scss预编译的项目
    ASP.Net Core WebApi几种版本控制对比
    解决Asp.Net Core 3.1 中无法读取HttpContext.Request.Body的问题
    winrar压缩文件但是排除指定目录
    postgresql数据库下导入导出,删除常用命令
    .NetCore使用Swagger+API多版本控制
    ElementUI和Ant Design对比
    自动登录或7天登录的实现
    浏览器脚本按钮功能
  • 原文地址:https://www.cnblogs.com/tuyile006/p/3297017.html
Copyright © 2011-2022 走看看