private void button1_Click(object sender, EventArgs e)
{
loginPageBindingSource.EndEdit();
int pcode = 0;
pcode = int.Parse(pincode.Text);
personalbalancesheet.BalanceSheetDataSet1TableAdapters.LoginPageTableAdapter myadapter = new personalbalancesheet.BalanceSheetDataSet1TableAdapters.LoginPageTableAdapter();
try
{
myadapter.Insert(name.Text, loginname.Text, password.Text, add1.Text, add2.Text, phoneno.Text, city.Text, statebox.Text, pcode);
开发者_开发知识库 MessageBox.Show("Data Inserted");
}
catch (Exception ex)
{
MessageBox.Show("inserion failed");
}
}
Edit: Adding more details from comments
The above code is not working , as I am trying to save the values from text boxes to database... Tthere are no compile or runtime errors but the database does not get updated. Output shown is "data inserted".
The code is this much only. Insert()
is a library method. Can you provide me with any alternative code for the data insertion in database?
One possiblity is the data mapping layer you're using hasn't committed the transaction to the database. So though your insert method appears to succeed, nothing would have changed in the actual database.
EDIT:
Assuming you're using a TableAdapter as your variable name suggests, then you need to call TableAdapter.Update()
to actually persist the data to the database. Here's a code sample from MSDN:
try
{
this.Validate();
this.customersBindingSource.EndEdit();
this.customersTableAdapter.Update(this.northwindDataSet.Customers);
MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}
MSDN - How to: Update Data Using a TableAdapter
精彩评论