zoukankan      html  css  js  c++  java
  • SQLite带参数处理方法

    /// <summary>
            /// 执行语法[新增 修改  删除]
            /// </summary>
            /// <param name="sqlText">sql语法</param>
            /// <returns></returns>
            public async Task<int> ExecuteNoneQuery(string sqlText, SQLiteParameter[] spr)
            {
                SQLiteConnection cn = new SQLiteConnection(_datasource);
                //连接数据库
                cn.ConnectionString = GetSQLiteConnectionString(_datasource);
                cn.Open();
                SQLiteCommand cmd = new SQLiteCommand();
                cmd.Connection = cn;
                cmd.CommandText = sqlText;
                //多个参数
                foreach (SQLiteParameter sp in spr)
                {
                    cmd.Parameters.Add(sp);
                }
    
                int count = await cmd.ExecuteNonQueryAsync();
                cn.Close();
                return count;
            }
            /// <summary>
            /// 获取连接字符串
            /// </summary>
            /// <param name="datasource">连接字符串</param>
            /// <returns></returns>
            public string GetSQLiteConnectionString(string datasource)
            {
                //连接数据库
                SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder();
                connstr.DataSource = datasource;
                connstr.Password = "123456";//设置密码,SQLite ADO.NET实现了数据库密码保护
                return connstr.ToString();
            }

    Webconfig

    <connectionStrings>
    <add name="DefaultConnection" connectionString="DataBase//fang_cheng.db" />
    </connectionStrings>

    调用

                    SQLiteParameter[] spr = { new SQLiteParameter("@Code", productCode) };
                    affectRow = await ExecuteNoneQuery(sqlText, spr);
  • 相关阅读:
    模态对话框可能导致程序崩溃
    C++实现将字符串循环左移n个位置
    Android Gallery图片显示和文字提示及Menu 菜单
    android代码实现ScaleAnimation
    Android系统内存管理的问题
    android打电话发短信
    android开发之屏幕设置
    输入法
    黄金周
    气筒
  • 原文地址:https://www.cnblogs.com/siyunianhua/p/10937941.html
Copyright © 2011-2022 走看看