这是我的代码
s2="SELECT Notes From A WHERE ATotalNo =" + ComboBox1.SelectedItem +""
Dim cmd As OleDbCommand=New OleDbCommand(s2,myConnection1)
cmd.CommandText=s2 TextBox1.Text=Convert.ToInt32(cmd.ExecuteScalar()).ToString()
我收到以下错误: -
Erorr:标准表达式中的数据类型不匹配
答案 0 :(得分:0)
在SelectedItem上应用ToString()
以及为什么要将结果集转换为整数,如果您只想在文本框中显示它?
试试这个,
s2 = "SELECT Notes From A WHERE ATotalNo = "& ComboBox1.SelectedItem.ToString() &""
Dim cmd As OleDbCommand = New OleDbCommand(s2, myConnection1)
cmd.CommandText = s2
TextBox1.Text = "" & cmd.ExecuteScalar()
此处结果集与空字符串连接,使其成为整个字符串。
如果列ATotalNo
的类型为VARCHAR,则用单引号装饰selectedItem值。像,
s2 = "SELECT Notes From A WHERE ATotalNo = '"& ComboBox1.SelectedItem.ToString() &"'"
希望它有所帮助。