.net 如何向SQLLite命令添加参数
我正在使用vs2008和SQLLite.Net, 当我使用这些代码时:.net 如何向SQLLite命令添加参数,.net,sqlite,.net,Sqlite,我正在使用vs2008和SQLLite.Net, 当我使用这些代码时: String sel = "select * from admins where [name]='admin88' and [password]='123456'"; System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(); conn.ConnectionString = Config.connStr; conn
String sel = "select * from admins where [name]='admin88' and [password]='123456'";
System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();
conn.ConnectionString = Config.connStr;
conn.Open();
System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
cmd.CommandText = sel;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
DataSet set = new DataSet();
System.Data.SQLite.SQLiteDataAdapter adp = new System.Data.SQLite.SQLiteDataAdapter() ;
adp.SelectCommand = cmd;
adp.Fill(set);
adp.Dispose();
Response.Write(set.Tables.count);
它起作用了。
但当我使用参数时,返回null:
String sel = "select * from admins where [name]=@name and [password]=@pass";
cmd.Parameters.Clear();
cmd.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@name", "admin88"));
cmd.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@pass", "123456"));
参考:
:AAAA后跟标识符名称的冒号保留命名名称的位置
名称为AAAA的参数。命名参数也被编号
您的查询应为:
String sel = "select * from admins where [name]= :name and [password]= :pass";
添加不带@符号的参数。检查以下代码段
SQLiteParameter[] myParams = new SQLiteParameter[]
{
new SQLiteParameter("DeptNo", 10),
new SQLiteParameter("DName", "COUNTING")
};
SQLiteConnection sqConnection1 = new SQLiteConnection("DataSource=mydatabase.db");
CreateCommand(sqConnection1,"UPDATE Dept SET DName = :DName WHERE DeptNo = :DeptNo",myParams);
参考。参考:
:AAAA后跟标识符名称的冒号保留命名名称的位置
名称为AAAA的参数。命名参数也被编号
您的查询应为:
String sel = "select * from admins where [name]= :name and [password]= :pass";
添加不带@符号的参数。检查以下代码段
SQLiteParameter[] myParams = new SQLiteParameter[]
{
new SQLiteParameter("DeptNo", 10),
new SQLiteParameter("DName", "COUNTING")
};
SQLiteConnection sqConnection1 = new SQLiteConnection("DataSource=mydatabase.db");
CreateCommand(sqConnection1,"UPDATE Dept SET DName = :DName WHERE DeptNo = :DeptNo",myParams);
参考资料