c#我想把查询语句的结果填写到textbox中去,但是运行后总说:标准表达式中数据类型不匹配。代码如下:
privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){Stringmyconstring=...
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
String myconstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";//连接数据库字符串
myconstring += Application.StartupPath + @"\db1.mdb";//连接数据库路径和数据库名
OleDbConnection mycon = new OleDbConnection(myconstring);
mycon.Open();
string sql1 = "select 课程名 from 课程表 where 课程号='" + comboBox1.Text + "'";
OleDbCommand mycomd = new OleDbCommand(sql1, mycon);
OleDbDataReader dr = mycomd.ExecuteReader();
while (dr.Read())
{
this.textBox1.Text = dr.GetString(0);
}
dr.Close();
mycon.Close();
mycon.Dispose();
} 展开
{
String myconstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";//连接数据库字符串
myconstring += Application.StartupPath + @"\db1.mdb";//连接数据库路径和数据库名
OleDbConnection mycon = new OleDbConnection(myconstring);
mycon.Open();
string sql1 = "select 课程名 from 课程表 where 课程号='" + comboBox1.Text + "'";
OleDbCommand mycomd = new OleDbCommand(sql1, mycon);
OleDbDataReader dr = mycomd.ExecuteReader();
while (dr.Read())
{
this.textBox1.Text = dr.GetString(0);
}
dr.Close();
mycon.Close();
mycon.Dispose();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询