【发布时间】:2016-01-30 00:17:57
【问题描述】:
我有几个从不同表中提取数据的依赖组合框 (CB)。它可以是选定值或查找值。例如,我将在框中显示文本(名称),选中后,我需要查找相应的 int(ID)并在查询中使用该值来填充下一个组合框。
我在引用命令/查询结果时遇到了问题,并且遇到了数据类型错误。错误是:
SQL passthru 表达式 ... 使用等号 (=) 具有不同数据类型的组件。
注意:我的 oledb 接口不支持 ICommandWithParameters
// Get the ID (int) value - This works as I can convert the return value to a string and echo back to the screen
OleDbCommand tblRow2 = new OleDbCommand("select ID from Table1 where NM= '"+ CB1.Text +"' ;" , conn3);
try
{
conn3.Open();
string r2 = Convert.ToString(tblRow2.ExecuteScalar());
MessageBox.Show(r2);
labelTableID.Text = "ID Code= " + r2;
conn3.Close();
}
catch (Exception ex2)
{
MessageBox.Show("Error " + ex2);
}
// Pass the ID (int) value and populate the next combo box CB2
// This doesn't work and throws the data type mismatch error
OleDbCommand tblRow3 = new OleDbCommand("select STATUS from Table2 where TABLE_ID = '"+ tblRow2 +"'; ",conn3);
OleDbDataReader rdRow3;
try
{
conn3.Open();
rdRow3 = tblRow3.ExecuteReader();
while (rdRow3.Read())
{
CB2.Items.Add(rdRow3.GetString(0));
}
conn3.Close();
}
【问题讨论】:
-
不知道为什么第二组代码没有正确显示...如果混淆我可以重新发布。