I have a very basic database and I'm using LinqToSQL. The problem is that when I try to add a new entity to the database, it doesn't commit the changes. Here's the code I have:
try
{
Customer cus = new Customer()
{
FirstName = txt_Fname.Text,
LastName = txt_Lname.Text,
Email = txt_Email.Text,
EveningPhone = txt_EveningPhone.Text,
DayPhone = txt_DayPhone.Text,
Company = txt_Company.Text,
City = txt_City.Text,
Country = country_select.Value,
Fax = txt_Fax.Text,
PostalCode = txt_POBox.Text,
Street = txt_Street.Text,
Password = txt_Password.Text
};
DataClassesDataContext db = new DataClassesDataContext();
db.Customers.InsertOnSubmit(cus);
db.SubmitChanges();
}
catch (Exception exp)
{
this.lbl_error.Text = exp.ToString();
}
It's not throwing any errors, no exceptions ... etc ...
All I did is that I added a new LinqToSQL item to my project, and I threw in the tables I need. Is there anything else I should do? Why it's not adding the customer to the database?
Question
Bazenga
Hello,
I have a very basic database and I'm using LinqToSQL. The problem is that when I try to add a new entity to the database, it doesn't commit the changes. Here's the code I have:
try { Customer cus = new Customer() { FirstName = txt_Fname.Text, LastName = txt_Lname.Text, Email = txt_Email.Text, EveningPhone = txt_EveningPhone.Text, DayPhone = txt_DayPhone.Text, Company = txt_Company.Text, City = txt_City.Text, Country = country_select.Value, Fax = txt_Fax.Text, PostalCode = txt_POBox.Text, Street = txt_Street.Text, Password = txt_Password.Text }; DataClassesDataContext db = new DataClassesDataContext(); db.Customers.InsertOnSubmit(cus); db.SubmitChanges(); } catch (Exception exp) { this.lbl_error.Text = exp.ToString(); }It's not throwing any errors, no exceptions ... etc ...
All I did is that I added a new LinqToSQL item to my project, and I threw in the tables I need. Is there anything else I should do? Why it's not adding the customer to the database?
thanks.
Link to comment
Share on other sites
13 answers to this question
Recommended Posts