两个问题请问一下各位专家
1.使用ado.net透过查询数据名称,将值赋予combox,但是未成功
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string UserAccount = this.dataGridView1.CurrentCell.Value.ToString();
label1.Text = this.dataGridView1.CurrentCell.Value.ToString();
string selectTable = " SELECT TABLE_NAME FROM information_schema.TABLES WHERE (TABLE_NAME LIKE ' " + UserAccount + " %') AND
(TABLE_NAME <>'%basic%')";
string strConn = Properties.Settings.Default.csEnergysaver.ToString();
MySqlConnection mycon = new MySqlConnection(strConn);
mycon.Open(); MySqlCommand mycmd = new MySqlCommand(selectTable, mycon);
MySqlDataReader myreader = mycmd.ExecuteReader(); //myreader 为 null while (myreader.Read())
cbShowChiller.Items.Add(myreader.Read());
mycon.Close();
}2. 透过下列SQL语法SELECT TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_NAME LIKE '00010000001%' AND TABLE_NAME <> '%basic%';可产生下列结果,我现在尝试查询时透过TABLE_NAME <> '%basic%' 过滤掉 '00010000001_1_basic_2008' 这行,但是结果还是有出来这行'00010000001_1_basic_2008''00010000001_1_basic_2008' ->应该被过滤掉,但是没有
'00010000001_1_chiller_0_2008'
'00010000001_1_chiller_1_2008'
'00010000001_1_chiller_2_2008'
'00010000001_1_chiller_3_2008'
'00010000001_1_chiller_4_2008'
'00010000001_1_chiller_5_2008'
'00010000001_1_chiller_6_2008'
'00010000001_1_chiller_7_2008'我应该还要修改哪里,谢谢各位专家。
1.使用ado.net透过查询数据名称,将值赋予combox,但是未成功
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string UserAccount = this.dataGridView1.CurrentCell.Value.ToString();
label1.Text = this.dataGridView1.CurrentCell.Value.ToString();
string selectTable = " SELECT TABLE_NAME FROM information_schema.TABLES WHERE (TABLE_NAME LIKE ' " + UserAccount + " %') AND
(TABLE_NAME <>'%basic%')";
string strConn = Properties.Settings.Default.csEnergysaver.ToString();
MySqlConnection mycon = new MySqlConnection(strConn);
mycon.Open(); MySqlCommand mycmd = new MySqlCommand(selectTable, mycon);
MySqlDataReader myreader = mycmd.ExecuteReader(); //myreader 为 null while (myreader.Read())
cbShowChiller.Items.Add(myreader.Read());
mycon.Close();
}2. 透过下列SQL语法SELECT TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_NAME LIKE '00010000001%' AND TABLE_NAME <> '%basic%';可产生下列结果,我现在尝试查询时透过TABLE_NAME <> '%basic%' 过滤掉 '00010000001_1_basic_2008' 这行,但是结果还是有出来这行'00010000001_1_basic_2008''00010000001_1_basic_2008' ->应该被过滤掉,但是没有
'00010000001_1_chiller_0_2008'
'00010000001_1_chiller_1_2008'
'00010000001_1_chiller_2_2008'
'00010000001_1_chiller_3_2008'
'00010000001_1_chiller_4_2008'
'00010000001_1_chiller_5_2008'
'00010000001_1_chiller_6_2008'
'00010000001_1_chiller_7_2008'我应该还要修改哪里,谢谢各位专家。
是否有得到值
FROM information_schema.TABLES
WHERE TABLE_NAME LIKE '00010000001%' AND TABLE_NAME not like '%basic%';
cbShowChiller.Items.Add(myreader["TABLE_NAME"].ToString());
换成这样看看
1.是有值的,当我dataGridView.CellClick是有值出现。
2.谢谢你的帮忙,是可行的。to linekery
还是没有值出现,我担心是这一行,因为myreader 为 null,combox没有值产生MySqlDataReader myreader = mycmd.ExecuteReader(); //myreader 为 null
(TABLE_NAME <>'%basic%')";
设置个断点
然后调试看看,把调试中的 selectTable 的值Copy到Sql看有没有得到值