读取数据库出错

lucksea521 2009-05-07 06:38:03
OleDbConnection thisconn01 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "/CnEduCode.mdb");

OleDbCommand mycomm01 = new OleDbCommand();

mycomm01.Connection = thisconn01;
//mycomm1.Connection = thisconn1;


if (radioButton1.Checked)
{

mycomm01.CommandText = "select Cn_BuildTime,Cn_ReturnCode0,CnreturnCode1,Cn_VerifyCode0,Cn_VerifyCode1,Cn_RegTime0,Cn_RegTime1 From Cn_License Where Cn_LicStr='" + textBox1.Text.Trim() + "'";

thisconn01.Open();
OleDbDataReader thisread01 = mycomm01.ExecuteReader();
if (thisread01.Read())
{
//转化并在datagridview中显示
string xlhsj001 = Convert.ToString(thisread01["Cn_BuildTime"]);
string jqyjm001 = Convert.ToString(thisread01["Cn_ReturnCode0"]);
string jqyjm002 = Convert.ToString(thisread01["Cn_ReturnCode1"]);
string zch001 = Convert.ToString(thisread01["Cn_VerifyCode0"]);
string zch002 = Convert.ToString(thisread01["Cn_VerifyCode1"]);
string zcsj001 = Convert.ToString(thisread01["Cn_RegTime0"]);
string zcsj002 = Convert.ToString(thisread01["Cn_RegTime1"]);
dataGridView1.Rows.Add(textBox1.Text.Trim(), xlhsj001, jqyjm001, jqyjm002, zch001, zch002, zcsj001, zcsj002);
thisconn01 .Close ();
return;


}
else
{
MessageBox.Show("此人不存在!");
return;
}

}




为什么到 OleDbDataReader thisread01 = mycomm01.ExecuteReader();过不去呢?
提示"至少一个参数未指定值"
难道我还要先判断textbox.text.trim()在数据库存在与否,再根据情况是否读取与textbox.text要关联的数据?
谢谢!
...全文
206 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lucksea521 2009-05-08
  • 打赏
  • 举报
回复
自己写错了!
zealot1021 2009-05-08
  • 打赏
  • 举报
回复
恩,明显的毛病看不出来,就是SQL语句看着不舒服
聖少俊 2009-05-07
  • 打赏
  • 举报
回复
应该是SQL语句错了 调试一下 看看SQL语句错没错
rizher 2009-05-07
  • 打赏
  • 举报
回复
字段名称没错吧
terrydio 2009-05-07
  • 打赏
  • 举报
回复
我倒,不知道下面的能不能解决,但我觉得楼主的数据库设计和程序设计都有点问题啊,怎么字段名和变量名都是这样啊,一看就不是很舒服啊!自己都容易乱啊!
因为你的是access字段,如果要把Cn_LicStr作为条件字段的时候,你应该在Select列表中加入它,你试下下面的语句,看看行不行,我以前好像也碰到过这样的问题!

mycomm01.CommandText = "select Cn_BuildTime,Cn_ReturnCode0,CnreturnCode1,Cn_VerifyCode0,Cn_VerifyCode1,Cn_RegTime0,Cn_RegTime1 ,Cn_LicStr From Cn_License Where Cn_LicStr='" + textBox1.Text.Trim() + "'";
JonasFeng 2009-05-07
  • 打赏
  • 举报
回复
楼主的SQL语句有问题。

搂着可以单独把SQL语句拿出来放在查询分析器里面分析下,

问题就出来了。
wuyq11 2009-05-07
  • 打赏
  • 举报
回复
SQL语句与数据库字段对应不起来或表中没有该字段
蓝海D鱼 2009-05-07
  • 打赏
  • 举报
回复
检查一下 这个SQL 语句 是否 有问题

mycomm01.CommandText = "select Cn_BuildTime,Cn_ReturnCode0,CnreturnCode1,Cn_VerifyCode0,Cn_VerifyCode1,Cn_RegTime0,Cn_RegTime1 From Cn_License Where Cn_LicStr='" + textBox1.Text.Trim() + "'";


110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧