TableAdapter.Update will not save my data
-
Okay I can't get my update to work. here is my code: namespace DBWinVoice { public partial class Company : Form { WinVoiceDataSet companyDS = new WinVoiceDataSet(); public Company() { InitializeComponent(); } private void Company_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'winVoiceDataSet.Company' table. You can move, or remove it, as needed. this.companyTableAdapter.Fill(this.winVoiceDataSet.Company); } private void button1_Click(object sender, EventArgs e) { try { this.companyBindingSource.EndEdit(); this.companyTableAdapter.Update(this.companyDS); MessageBox.Show("Update Successful"); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } } } } I know I am doing something dumb...can anyone help me? Thanks
Christopher J. Thornburg Senior Systems Analyst Ideal Card
-
Okay I can't get my update to work. here is my code: namespace DBWinVoice { public partial class Company : Form { WinVoiceDataSet companyDS = new WinVoiceDataSet(); public Company() { InitializeComponent(); } private void Company_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'winVoiceDataSet.Company' table. You can move, or remove it, as needed. this.companyTableAdapter.Fill(this.winVoiceDataSet.Company); } private void button1_Click(object sender, EventArgs e) { try { this.companyBindingSource.EndEdit(); this.companyTableAdapter.Update(this.companyDS); MessageBox.Show("Update Successful"); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } } } } I know I am doing something dumb...can anyone help me? Thanks
Christopher J. Thornburg Senior Systems Analyst Ideal Card
What are the error messages, if any?? Define how it's "not working". Does this table have a primary key that is returned by the SELECT statement?? The adapters won't work without it. The Adapters write the changes back to the database by executing the INSERT, DELETE, and UPDATE command for each line in the table that needs updating. Without a primary key in your table, AND without that key being part of the resulting recordset, there is no way for the TableAdapter to tell the SQL database which record to update and how to do it.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
What are the error messages, if any?? Define how it's "not working". Does this table have a primary key that is returned by the SELECT statement?? The adapters won't work without it. The Adapters write the changes back to the database by executing the INSERT, DELETE, and UPDATE command for each line in the table that needs updating. Without a primary key in your table, AND without that key being part of the resulting recordset, there is no way for the TableAdapter to tell the SQL database which record to update and how to do it.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Yes I have a primary key. I am not getting any error messages it just will not work. I have just added tables to my dataset so I need to change my code a bit. Would this work better if I used a datatable variable assigned my company table and then passed the datatable to the update or should I use datarows????? I just want you to know I have no idea what I am doing....:) I am a little confused about the whole thing.
Christopher J. Thornburg
-
Yes I have a primary key. I am not getting any error messages it just will not work. I have just added tables to my dataset so I need to change my code a bit. Would this work better if I used a datatable variable assigned my company table and then passed the datatable to the update or should I use datarows????? I just want you to know I have no idea what I am doing....:) I am a little confused about the whole thing.
Christopher J. Thornburg
You're passing an empty DataSet to the update method. You intialize companyDS as new and then never assign any data to it. That's why there is no error. It is successfully updating with an empty DataSet into a database (that presumably) allows NULL values or empty strings.
-
You're passing an empty DataSet to the update method. You intialize companyDS as new and then never assign any data to it. That's why there is no error. It is successfully updating with an empty DataSet into a database (that presumably) allows NULL values or empty strings.
Okay cool...will you show me how to do it???? I think I would need a dataset.table variable and then assign it the data of the current row, and then pass that to the tableadapter.update() is this right? can you show me how you would do it in some code. I have 4 tables in my dataset. Dataset = WinVoiceDataSet Table = Company
Christopher J. Thornburg