日期:2014-05-18  浏览次数:20755 次

关于使用C#数据库连接的问题
兄弟们好,我最近正学着使用C#编写程序,想连接一个用MySql建立的数据库,库名为jopens 表为waveform 怎么建立给个例子代码就行呀,谢谢

------解决方案--------------------
http://blog.sina.com.cn/s/blog_43eb83b90100mb08.html
------解决方案--------------------
private void Form1_Load(object sender, EventArgs e)

{


MySQLConnection conn = null;

conn = new MySQLConnection(new MySQLConnectionString("localhost", "inv", "root", "831025").AsString);

conn.Open();


MySQLCommand commn = new MySQLCommand("set names gb2312", conn);

commn.ExecuteNonQuery();


string sql = "select * from waveform ";

MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);


DataSet ds = new DataSet();

mda.Fill(ds, "table1");


this.dataGrid1.DataSource = ds.Tables["table1"];

conn.Close();


}