日期:2014-05-17 浏览次数:21124 次
server = "localhost"; database = "csharp"; name = "root"; password = "root"; string connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + name + ";" + "PASSWORD=" + password + ";"; connection = new MySqlConnection(connectionString); string mysql = "select * from books"; MySqlDataAdapter mysqlAdapter = new MySqlDataAdapter(mysql, connection); DataSet ds = new DataSet(); mysqlAdapter.Fill(ds); dataGridView1.DataSource = ds.Tables[0].DefaultView; connection.Close(); connection.Dispose();
select * from books --把*号写成字段名试一试 应该不是Gridview的问题
------解决方案--------------------
你先在datagridview控件中设置好列名,然后再绑定试试看。
------解决方案--------------------
MySQLCommand com = new MySQLCommand("set names gb2312", conn);