如何在C#网格视图中显示Mysql数据库这里是我的代码片段,它不显示任何内容 [英] How Do I Show Mysql Database In C# Grid View Here Is My Piece Of Code This Displays Nothing
本文介绍了如何在C#网格视图中显示Mysql数据库这里是我的代码片段,它不显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void frmpatient_Load(object sender, EventArgs e)
{
con = new MySqlConnection();
con = dbcon.openconnection();
showdatabase();
}
public void showdatabase() {
con.Open();
ds = new DataSet();
cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM `Ptient`";
da = new MySqlDataAdapter(cmd);
da.Fill(ds, "st");
dataGridViewpatient.DataSource = ds;
dataGridViewpatient.DataMember = "st";
con.Close();
}
推荐答案
private void frmpatient_Load(object sender, EventArgs e)
{
if (!(IsPostBack))
{
con = new MySqlConnection();
con = dbcon.openconnection();
showdatabase();
}
}
< b>检查IsPostBack属性。
大家好我很抱歉我的错误我已经在一个单独的类中创建了连接并再次编码新的Mysqlconnection:D这是我的错误任何我如何找到问题
//数据库连接
Hi every one i am sorry its my mistake i have created the connection already in a separate class and again i have been coded new Mysqlconnection :D that's my mistake any how i sought out the problem
//database connection
MySqlConnection con;
dbconnection dbcon = new dbconnection();
MySqlDataAdapter da;
DataSet ds;
public frmpatient()
{
InitializeComponent();
}
private void frmpatient_Load(object sender, EventArgs e)
{
showdatabase();
}
public void showdatabase() {
con = dbcon.openconnection();
con.Open();
MessageBox.Show("Connection ok");
da = new MySqlDataAdapter("select * from actor",con);
ds = new DataSet();
da.Fill(ds);
dataGridViewpatient.DataSource = ds.Tables[0];
con.Close();
}
这篇关于如何在C#网格视图中显示Mysql数据库这里是我的代码片段,它不显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文