Datatable empty after update and refill after MySQL 5.1
Posted by: Intanont Triudom
Date: July 27, 2016 07:16PM

I have a problem re-selecting with a DataTable after adding a new row. The ms_perhist table is not empty, but after the button1_Click event the DataGridView1 shows columns from ms_perhist, but with 0 rows.The I tested with 2 versions of MySQL and MySQL 5.0 displays the table correctly. What should I do to make the data appear in later versions of MySQL?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace MySQL_Test
public partial class Form1 : Form
public Form1()

public MySqlConnection connection;
public DataTable table1;
public MySqlDataAdapter adapter1;
public MySqlCommandBuilder cmb1;

public void opentable(String sql)
adapter1 = new MySqlDataAdapter(sql, connection);
cmb1 = new MySqlCommandBuilder(adapter1);
table1 = new DataTable();

private void Form1_Load(object sender, EventArgs e)
connection = new MySqlConnection("User ID=XXX;Password=XXX;Connection Timeout=28800;Character Set=utf8;Data Source=XXX;Database=XXX;Port=3306;Compress=True");
dataGridView1.DataMember = "ms_per";

private void button1_Click(object sender, EventArgs e)
opentable("SELECT * FROM ms_per WHERE PerCode='001'");
DataRow newrow = table1.NewRow();
newrow["PerCode"] = "001";
opentable("SELECT * FROM ms_perhist");
dataGridView1.DataSource = table1;

Options: ReplyQuote

Written By
Datatable empty after update and refill after MySQL 5.1
July 27, 2016 07:16PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.