我希望将数据表从数据库加载到数据网格视图,但是我得到的错误是"操作&方法未实施"。我在这里查看视频:http://www.youtube.com/watch?v=Sm5mxkytfWk;这是我第一次这样做,希望能够解决它。
以下是我的代码:
private void button1_Click(object sender, EventArgs e)
{
string constring = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\oo\Documents\Data.mdf;Integrated Security=True;Connect Timeout=30";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand("SELECT* from Data.itemInfo;", conDataBase);
try
{
MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = cmdDataBase;
DataTable dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dataGridView1.DataSource = bSource;
sda.Update(dbdataset);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
答案 0 :(得分:0)
MySqlCommand cmdDataBase = new MySqlCommand("SELECT* from Data.itemInfo;", conDataBase);
你的SQL查询包含额外的分号
这
SELECT* from Data.itemInfo;
到
SELECT* from Data.itemInfo