KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm currently working on a project using MySql in combination with C#. The Data for the DataGridView is provided by a join from multiple tables in the DB. To show the data I use the following, working, code: adapter.SelectCommand = new MySqlCommand( " SELECT" + " l.lot AS Lot, "+ " m.comment AS Bemerkungen," + ... (multiple columns from different tables) ... " FROM m " + " JOIN m2p ON m.m2p_id = m2p.id" + ... (more joins) ... , this._mySqlConnection); dataGridView1.DataSource = data; adapter.Fill(data); Now the user of the GUI is allowed to modify a certain column (the "comment" column). So I assigned an eventHandler to the CellEndEdit event and when the user modified the allowed column the adapter.Update(data) is called. Now this doesn't perform the correct action. To define my updatecommand I used the following code: adapter.UpdateCommand = new MySqlCommand( " UPDATE m" + " JOIN l ON m.l_id = l.id" + " SET m.comment = @comment" + " WHERE l.lot = @lot" , this._mySqlConnection); adapter.UpdateCommand.Parameters.Add("@comment", MySqlDbType.Text, 256, "Bemerkungen"); adapter.UpdateCommand.Parameters.Add("@lot", MySqlDbType.Text, 256, "Lot"); Could you explain me how I fix my code to automatically Update the database? EDIT: added further source code: private MySqlDataAdapter warenlagerMySqlDataAdapter, kundenMySqlDataAdapter; private DataTable warenlagerData, kundenData; private DataGridView warenlagerGridView; private void updateWarenlagerView(object sender, EventArgs e) { warenlagerMySqlDataAdapter.Update(warenlagerData); } private void initialzeFields() { warenlagerGridView.CellEndEdit += new DataGridViewCellEventHandler(this.updateWarenlag
Tags (comma-separated)
Save Edits
Cancel