请大家帮我看看下面的查询语句哪个地方出错了,数据库连接没错,读取数据的记录是空的富有文本框中只显示helloworld
OleDbConnection conn2 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\\jwsjk.mdb");
conn2.Open();
//string sql2 = "select 从属字 from bsbm ";
OleDbCommand cmd2 = new OleDbCommand();
cmd2.Connection = conn2;
cmd2.CommandText = "select 从属字 from bsbm where 字目编码 like'001002___'";
cmd2.CommandType = CommandType.Text;
OleDbDataReader sdr2 = cmd2.ExecuteReader();
if (sdr2.Read() == false)
{
MessageBox.Show("该字没有从属字!");
return;
}
else
{
richTextBox1.Text = sdr2[0].ToString();
richTextBox1.Text = "hello world";
}
while (sdr2.Read())
{
richTextBox1.Text += sdr2[0].ToString();
}
conn2.Close();
sdr2.Close();
cmd2.Dispose();
------解决方案--------------------richTextBox1.Text = sdr2[0].ToString();
richTextBox1.Text = "hello world";
你这是2此赋值,不是把前面的内容覆盖了吗,去掉
richTextBox1.Text = "hello world";
------解决方案--------------------richTextBox1.Text += sdr2[0].ToString();
richTextBox1.Text += "hello world";
这样试一试
------解决方案--------------------sql语句在数据库里直接执行,能查出结果么
------解决方案--------------------C# code
if (sdr2.HasRows)
{
while (sdr2.Read())
{
richTextBox1.Text=sdr2[0].ToString();
}
}
sdr2.Close();
conn2.Close();