Ejemplo n.º 1
0
		/// <summary>
		/// Updates the given table with data from the given <see cref="DataSet"/>
		/// </summary>
		/// <param name="connectionString">Settings to use for the update</param>
		/// <param name="commandText">Command text to use for the update</param>
		/// <param name="ds"><see cref="DataSet"/> containing the new data to use in the update</param>
		/// <param name="tablename">Tablename in the dataset to update</param>
		public static void UpdateDataSet( string connectionString, string commandText, DataSet ds, string tablename )
		{
			MySqlConnection cn = new MySqlConnection( connectionString );
			cn.Open();
			MySqlDataAdapter da = new MySqlDataAdapter( commandText, cn );
			MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
			cb.ToString();
			da.Update( ds, tablename );
			cn.Close();
		}
Ejemplo n.º 2
0
        public static void UpdateDataSet(string connectionString, string commandText, DataSet ds, string tablename)
        {
            MySqlConnection mySqlConnection = new MySqlConnection(connectionString);

            mySqlConnection.Open();
            MySqlDataAdapter    mySqlDataAdapter    = new MySqlDataAdapter(commandText, mySqlConnection);
            MySqlCommandBuilder mySqlCommandBuilder = new MySqlCommandBuilder(mySqlDataAdapter);

            mySqlCommandBuilder.ToString();
            mySqlDataAdapter.Update(ds, tablename);
            mySqlConnection.Close();
        }
        public void UpdateNullTextFieldToEmptyString()
        {
            CreateDefaultTable();
              execSQL("INSERT INTO Test (id, id2, name) VALUES (1, 1, NULL)");

              MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
              MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
              cb.ToString();  // keep the compiler happy

              DataTable dt = new DataTable();
              da.Fill(dt);

              dt.Rows[0]["name"] = "";
              int updateCnt = da.Update(dt);

              Assert.AreEqual(1, updateCnt);

              dt.Rows.Clear();
              da.Fill(dt);

              Assert.AreEqual(1, dt.Rows.Count);
              Assert.AreEqual("", dt.Rows[0]["name"]);
        }
        public void UpdateExtendedTextFields()
        {
            execSQL("CREATE TABLE Test (id int, notes MEDIUMTEXT, PRIMARY KEY(id))");
              execSQL("INSERT INTO Test VALUES(1, 'This is my note')");

              MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
              MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
              cb.ToString();  // keep the compiler happy
              DataTable dt = new DataTable();
              da.Fill(dt);

              dt.Rows[0]["notes"] = "This is my new note";
              da.Update(dt);

              dt.Clear();
              da.Fill(dt);
              Assert.AreEqual("This is my new note", dt.Rows[0]["notes"]);
        }
        public void OriginalInName()
        {
            CreateDefaultTable();
              MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
              MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
              cb.ToString();  // keep the compiler happy
              DataTable dt = new DataTable();
              da.Fill(dt);

              DataRow row = dt.NewRow();
              row["id"] = DBNull.Value;
              row["id2"] = 1;
              row["name"] = "Test";
              row["dt"] = DBNull.Value;
              row["tm"] = DBNull.Value;
              row["ts"] = DBNull.Value;
              row["OriginalId"] = 2;
              dt.Rows.Add(row);
              da.Update(dt);

              Assert.AreEqual(1, dt.Rows.Count);
              Assert.AreEqual(2, dt.Rows[0]["OriginalId"]);
        }
        public void Bug5798()
        {
            CreateDefaultTable();
              execSQL("INSERT INTO Test (id, id2, name) VALUES (1, 1, '')");

              MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
              MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
              cb.ToString();  // keep the compiler happy
              DataTable dt = new DataTable();
              da.Fill(dt);

              Assert.AreEqual(String.Empty, dt.Rows[0]["name"]);

              dt.Rows[0]["name"] = "Test";
              da.Update(dt);

              dt.Clear();
              da.Fill(dt);
              Assert.AreEqual("Test", dt.Rows[0]["name"]);
        }
Ejemplo n.º 7
0
		/// <summary>
		/// Updates the given table with data from the given <see cref="DataSet"/>
		/// </summary>
		/// <param name="connectionString">Settings to use for the update</param>
		/// <param name="commandText">Command text to use for the update</param>
		/// <param name="ds"><see cref="DataSet"/> containing the new data to use in the update</param>
		/// <param name="tablename">Tablename in the dataset to update</param>
		public static void UpdateDataSet( string connectionString, string commandText, DataSet ds, string tablename )
		{
			MySqlConnection cn = new MySqlConnection( connectionString );
			cn.Open();
			MySqlDataAdapter da = new MySqlDataAdapter( commandText, cn );
			MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
			cb.ToString();
			da.Update( ds, tablename );
			cn.Close();
		}