上网找了好久,有的说是参数名字错了,有的说把"@parameter"改成"?"就可以了。
解决C#操作SQLite数据库时出现“Insufficient parameters supplied to the command”的错误
将如下SQL语句:
insert into tbl_stock(Title,Barcode,Price)
values(@Title,@Barcode,@Price)
改成:
insert into tbl_stock(Title,Barcode,Price)
values(?,?,?)注意:使用?代替@Title,其它等同。
https://blog.csdn.net/diligentcatrich/article/details/38027147
但是我之前用@parameter都可以,所以研究了很久。
结果发现是设置的参数长度太长了,改短就可以了。不知道具体原理。
//插入命令
string comUpdate = "insert into Class (code, className, campus, school, grade, contact, phoneNumber) " +
"values(@CODE, @CLASSNAME, @CAMPUS, @SCHOOL, @GRADE, @CONTACT, @PHONENUMBER)";
//这里的参数PHONENUMBER太长了
SQLiteCommand mycom = db.createCommand(comUpdate);
//添加参数
mycom.Parameters.Add(new SQLiteParameter("@CODE", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@CLASSNAME", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@CAMPUS", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@SCHOOL", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@GRADE", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@CONTACT", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@PHONENUMER", DbType.String));
//给参数赋值
mycom.Parameters["@CODE"].Value = code;
mycom.Parameters["@CLASSNAME"].Value = className;
mycom.Parameters["@CAMPUS"].Value = campus;
mycom.Parameters["@SCHOOL"].Value = school;
mycom.Parameters["@GRADE"].Value = grade;
mycom.Parameters["@CONTACT"].Value = contact;
mycom.Parameters["@PHONENUMER"].Value = phoneNumber;
//执行添加语句
mycom.ExecuteNonQuery();
将@PHONENUMBER改成@PHONE就可以了
//插入命令
string comUpdate = "insert into Class (code, className, campus, school, grade, contact, phoneNumber) " +
"values(@CODE, @CLASSNAME, @CAMPUS, @SCHOOL, @GRADE, @CONTACT, @PHONE)";
SQLiteCommand mycom = db.createCommand(comUpdate);
//添加参数
mycom.Parameters.Add(new SQLiteParameter("@CODE", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@CLASSNAME", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@CAMPUS", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@SCHOOL", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@GRADE", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@CONTACT", DbType.String));
mycom.Parameters.Add(new SQLiteParameter("@PHONE", DbType.String));
//给参数赋值
mycom.Parameters["@CODE"].Value = code;
mycom.Parameters["@CLASSNAME"].Value = className;
mycom.Parameters["@CAMPUS"].Value = campus;
mycom.Parameters["@SCHOOL"].Value = school;
mycom.Parameters["@GRADE"].Value = grade;
mycom.Parameters["@CONTACT"].Value = contact;
mycom.Parameters["@PHONE"].Value = phoneNumber;
//执行添加语句
mycom.ExecuteNonQuery();
提供一些其它的错误原因参考:
https://stackoverflow.com/questions/1584005/c-sharp-sqlite-error-insufficient-parameters-supplied-to-the-command
https://stackoverflow.com/questions/25008186/insufficient-parameters-supplied-to-the-command-error-when-executing-sqlite-qu
https://bbs.csdn.net/topics/360108597