Tuesday 15 September 2015

Update Database From DataGrid in C#.NET -


I have this code that I have used for the update database from DataGrid

  Using the system; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; Using System.Windows.Forms; Using MySql.Data.MySqlClient; Nameshot Ditgrid {Public Partial Class} Form 1: Form {Private MySQL Connection Connection; Personal dataable data; Private MySqlDataAdapter da; Private MySqlCommandBuilder CB; Public Form 1 () {Initialization (); } Private Zero btnshow_Click (Object Sender, EventArgs e) {string c = "server = localhost; database = std; uid = root; password ="; Conn = new MySqlConnection (c); Conn.Open (); Data = new datatile (); Da = New MySqlDataAdapter ("Select from Normal", Kon); Cb = new MySqlCommandBuilder (da); Da.Fill (data); DataGridView1.DataSource = Data; } Private Zero btnupdate_Click (Object Sender, EventArgs e) {DataTable changes = data.GetChanges (); Da.Update (change); Data.AcceptChanges (); }}}   

Now when I press the update button it shows me the exception:

{"Against the dynamic SQL generation one for UpdateCommand Not supported, choose Commands which does not return any important column information. "}

Now please tell me what should I do?

such exceptions

Many other articles from this

I am pretty sure that those exceptions mean that your selected query is of the table The primary key is required to be returned if you do not have a primary key in the table, then you have to set one.

Otherwise, you should manually create your DeleteCommand and UpdateCommand and assign them in the related properties.

No comments:

Post a Comment