Question

i am using sqlite for database in windows phone 7 i am using Community.CsharpSqlite.Wp third party dll

I created Customer Table which have fields like 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;
    }      
}

and My Insert statement is as below on button click

     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);

     }

This Code Works fine.. Value will be inserted to database.

But if i hard code values Like

"Insert into Customer (Name,Email,Desc) values ('ABCD','TEST@gmail.com','DESCRI')"

and my code changed like this

 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);
}

I am Getting Error " Insert failed: bind or column index out of range" in DBHelper.cs

Était-ce utile?

La solution

You are calling an generic overload that takes an object. From that object/type I assume the helper creates parameters that need to match the parameter placeholders in the actual sql statement.

If you want to Execute a SqliteCommand that doesn't have or need parameters use the overload that doesn't take an object, for example:

cmd.ExecuteNonQuery();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top