使用Mysqldataadapter.update()插入值 [英] insert the values using Mysqldataadapter.update( )

查看:764
本文介绍了使用Mysqldataadapter.update()插入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string InsertQuery = "";
                     MySqlTransaction transaction;
               MySqlConnection con1 = new MySqlConnection();
                     MySqlDataAdapter ODA;
                     string server = loggerConnectionString.servername;
con1.ConnectionString ="server="localhost";uid=root;pwd=;database=globasys;";

                     con1.Open();
                     transaction = con1.BeginTransaction();

                     ODA = new MySqlDataAdapter();

                     InsertQuery = "Insert into tr_config_unit_params " + Environment.NewLine;
                     InsertQuery += "(unit_param_id,unit_id, unit_param_desc, unit_param_opc_progid, unit_param_host, unit_param_link, unit_param_data_type, unit_param_type) " + Environment.NewLine;
                     InsertQuery += " VALUES(@unit_param_id,@unit_id,@unit_param_desc, @unit_param_opc_progid, @unit_param_host, @unit_param_link, @unit_param_data_type, @unit_param_type)";;
                     ODA.InsertCommand =new   MySqlCommand(InsertQuery, con1);
                     ODA.InsertCommand.Parameters.Add("@unit_param_id", MySqlDbType.Int32);
                     ODA.InsertCommand.Parameters.Add("@unit_id&quot", MySqlDbType.Int32);
                     ODA.InsertCommand.Parameters.Add("@unit_param_desc", MySqlDbType.VarChar);
                     ODA.InsertCommand.Parameters.Add("@unit_param_opc_progid", MySqlDbType.VarChar);
                     ODA.InsertCommand.Parameters.Add("@unit_param_host", MySqlDbType.VarChar);
                     ODA.InsertCommand.Parameters.Add("@unit_param_link", MySqlDbType.VarChar);
                     ODA.InsertCommand.Parameters.Add("@unit_param_data_type", MySqlDbType.Int32);
                     ODA.InsertCommand.Parameters.Add("@unit_param_type", MySqlDbType.Int32);

                     ODA.InsertCommand.Transaction = transaction;

                     DataSet ds = new DataSet();
                     ds = dt;

                  int y=   ODA.Update(ds,"param");


                     transaction.Commit();
                  con1.Close();
 </pre>

i have insert the 150000 rows using Mysqldataadapter.update() but the query execute successfully but there is no row insert into the database table in MYSQL

thanks in advance.....

推荐答案

您缺少调用DataSet.AcceptChanges的权限.自此数据集被加载以来或自上次调用AcceptChanges以来,此方法将落实对此数据集所做的所有更改.

您可以在此处 DataSet.AcceptChanges [
You are missing to call DataSet.AcceptChanges. This method commits all the changes made to this DataSet since it was loaded or since the last time AcceptChanges was called.

You can read more here DataSet.AcceptChanges[^]


这篇关于使用Mysqldataadapter.update()插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆