error in linq while saving to database

Posted by Klbaiju under ASP.NET on 2/7/2013 | Points: 10 | Views : 655 | Status : [Member] | Replies : 1
hi,
following is the code for save to database using linq
DataContext Db = new DataContext("Data Source=baiju-pc;Initial Catalog=Baiju;Integrated Security=True");
string msg = string.Empty;
customer objCustomer = new customer();
objCustomer.Id = Convert.ToInt32(TextBox1.Text.ToString());
objCustomer.name = TextBox2.Text;
objCustomer.address = TextBox3.Text;
try
{
Db.GetTable<customer>().InsertOnSubmit(objCustomer);
Db.SubmitChanges();
Label1.Text = "Inserted successfully";
}
catch (Exception ex)
{
msg = ex.Message;
Label1.Text = msg;
}
finally
{
Db.Dispose();
}
***************************************
[Table (Name="customer")]
public class customer
{
[Column (DbType="int",IsPrimaryKey=true)]
public int Id
{ get; set; }
[Column (DbType="nvarchar(50)")]
public string name
{ get; set; }
[Column (DbType="nvarchar(50")]
public string address
{ get; set; }

}
but error is showing
this is the error

Length cannot be less than zero.
Parameter name: length
what is the reason

Regards
Baiju




Responses

Posted by: Kusumas on: 2/8/2013 [Member] Starter | Points: 25

Up
0
Down
Hi ,

I think you not passing this value objCustomer.Id = Convert.ToInt32(TextBox1.Text.ToString());

check it once.

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response