Description:
Bug with DataAdapter Property of MySqlCommandBuilder class.
Using:
-----------------------
MySqlCommandBuilder cb=new MySqlCommandBuilder();
cb.DataAdapter=myDataAdapter1;
...
myDataAdapter.Update(dataSet1, "TableName");
-----------------------
gives an error :
A atualização requer um UpdateCommand válido para transmitir coleção DataRow com linhas modificadas.
"The Updating requery a valid UpdateCommand to transmit DataRow collection with modified lines."
How to repeat:
using System;
using System.Windows.Forms;
using System.Data;
using ByteFX.Data.MySqlClient;
using MySQLDriverCS;
namespace DefaultNamespace
{
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button2;
private MySqlDataAdapter da;
private DataSet ds;
private MySqlConnection conn;
public MainForm()
{
InitializeComponent();
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}
#region Windows Forms Designer generated code
private void InitializeComponent() {
this.button2 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button2.Location = new System.Drawing.Point(128, 232);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "Update";
this.button2.Click += new System.EventHandler(this.Button2Click);
//
// dataGrid1
//
this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(280, 208);
this.dataGrid1.TabIndex = 0;
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(216, 232);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 1;
this.button1.Text = "Retrieve";
this.button1.Click += new System.EventHandler(this.Button1Click);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataGrid1);
this.Name = "MainForm";
this.Text = "MainForm";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
void Button1Click(object sender, System.EventArgs e)
{
conn=new MySqlConnection("Database=cahti;Data Source=netserver;User Id=root;Password=xxx");
conn.Open();
da=new MySqlDataAdapter("SELECT * FROM cob_clientesaparthotel",conn);
MySqlCommandBuilder cb=new MySqlCommandBuilder();
-----------------------------------------------------------------------------
cb.DataAdapter=da; //does not work properly
-----------------------------------------------------------------------------
ds=new DataSet();
da.Fill(ds,"Clientes");
dataGrid1.SetDataBinding(ds,"Clientes");
}
void Button2Click(object sender, System.EventArgs e)
{
da.Update(ds, "Clientes");
}
}
}
Suggested fix:
Using:
-----------------------
MySqlCommandBuilder cb=new MySqlCommandBuilder(myDataAdapter1);
//cb.DataAdapter=myDataAdapter1;
...
myDataAdapter.Update(dataSet1, "TableName");
-----------------------
solve the problem.