• 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();
                    }
                }
            }
  • 相关阅读:
    brewhome
    WIN7下安装SQL server 2008 R2“出现性能计数器注册表配置单元一致性”失败的解决办法(新)
    话说ELK使用安装,结合.NET Core、ABP框架Nlog日志
    支付系统架构
    高可用Redis服务架构分析与搭建
    基于STS和JWT的微服务身份认证
    全面解读NoSQL数据库Redis的核心技术与应用实践
    Redis应用及安装
    微服务实践分享与探讨
    Docker的核心概念,镜像操作
  • 原文地址:https://www.cnblogs.com/tuyile006/p/3297017.html
Copyright © 2020-2023  润新知