Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

Datatable empty after update and refill after MySQL 5.1 (no replies)

$
0
0
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()
{
InitializeComponent();
}

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();
adapter1.Fill(table1);
}

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)
{
connection.Open();
opentable("SELECT * FROM ms_per WHERE PerCode='001'");
if(table1.Rows.Count==0)
{
DataRow newrow = table1.NewRow();
newrow["PerCode"] = "001";
table1.Rows.Add(newrow);
}
adapter1.Update(table1);
opentable("SELECT * FROM ms_perhist");
dataGridView1.DataSource = table1;
connection.Close();
}
}
}

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>