SQLite processing method with parameters

///  <the Summary> 
        /// performs syntax [New Laws Delete]
         ///  </ the Summary> 
        ///  <param name = "sqlText"> SQL syntax </ param> 
        ///  <returns A> </ returns A > 
        public  the async the Task < int > ExecuteNoneQuery ( String sqlText, SQLiteParameter [] SPR) 
        { 
            SQLiteConnection CN = new new SQLiteConnection (_datasource);
             // connect to the database 
            cn.ConnectionString = GetSQLiteConnectionString (_datasource); 
            the cn.Open (); 
            SQLiteCommand cmd = new 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> 
        /// Get Connection String
         ///  </ Summary> 
        ///  <param name = "DataSource"> connection string </ param> 
        ///  <Returns> </ Returns> 
        public  String GetSQLiteConnectionString ( String DataSource) 
        { 
            // connect to the database 
            SQLiteConnectionStringBuilder connstr = new new SQLiteConnectionStringBuilder (); 
            connstr.DataSource = DataSource; 
            connstr.Password = " 123456 " ; // set a password, SQLite ADO.NET database password protected to achieve 
            return connstr.ToString();
        }

Webconfig

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

 

transfer

                SQLiteParameter[] spr = { new SQLiteParameter("@Code", productCode) };
                affectRow = await ExecuteNoneQuery(sqlText, spr);

 

Guess you like

Origin www.cnblogs.com/siyunianhua/p/10937941.html