我在windows phone 7中使用sqlite for database 我正在使用Community.CsharpSqlite.Wp第三方dll
我创建了Customer Table,其中包含ID,Name,Email,Desc
等字段 public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Desc { get; set; }
public Customer() { }
public Customer(int Id, string name, string email, string desc)
{
ID = Id;
Name = name;
Email = email;
Desc = desc;
}
}
和我的插入语句如下点击按钮
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
string strInsert = " Insert into Customer (Name,Email,Desc) values(@Name,@Email,@Desc)";
Customer tst = new Customer
{
Name = "Name " + i,
Email = Name + "@" + "aaa.com",
Desc = "Desc for " + i
};
rec = (Application.Current as App).db.Insert < Customer>(tst,strInsert);
}
此代码工作正常..值将被插入数据库。
但是,如果我硬编码值像
“插入客户(姓名,电子邮件,说明)值('ABCD','TEST @ gmail.com','DESCRI')”
我的代码改变了这个
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
Customer tst = new Customer();
string strInsert = " Insert into Customer (Name,Email,Desc) values ('ABCD','TEST@gmail.com','DESCRI')";
rec = (Application.Current as App).db.Insert < Customer>(tst,strInsert);
}
我收到错误“插入失败:绑定或列索引超出范围” 在DBHelper.cs
中答案 0 :(得分:0)
您正在调用带有对象的泛型重载。从该对象/类型我假设帮助器创建的参数需要匹配实际sql语句中的参数占位符。
如果要执行不具有或不需要参数的SqliteCommand,请使用不会占用对象的重载,例如:
cmd.ExecuteNonQuery();