前缀数目超过最大值问题

slchen 2006-05-11 05:30:08
我照着书上作了一个例子,报错
System.Data.SqlClient.SqlException: 数字 名称 'System.Web.UI.WebControls' 包含的前缀数目超过了最大值。最大值为 3。
源程序
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

private void Button1_Click(object sender, System.EventArgs e)
{
DataSet ds;
SqlDataAdapter cmd;
SqlConnection Con=new SqlConnection("server=jszx-csl;database=人事库;User ID=sa;PWD=976722;connect timeout=120");
string sel="select * from 人员登陆参数表 where sno=" +TextBox1;
SqlCommand addCommand=new SqlCommand(sel,Con);
/*addCommand.Connection.Open();*/
Con.Open();
SqlDataReader selreader=addCommand.ExecuteReader();
/*

selreader=addCommand.ExecuteReader();*/
if(selreader.Read()==true)
Label3.Text="YES";
addCommand.Connection.Close();
}
}
}

SqlDataReader selreader=addCommand.ExecuteReader();这行出错,
[SqlException: 数字 名称 'System.Web.UI.WebControls' 包含的前缀数目超过了最大值。最大值为 3。]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
System.Data.SqlClient.SqlCommand.ExecuteReader()

为什么啊,我查找以前的帖子也是用的SqlDataReader,错哪了呢,怎样改阿?
...全文
165 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiaoci 2006-05-12
  • 打赏
  • 举报
回复
而且可以猜出你的TextBox1中的内容大概是这个样子的 ?

xxx.xxxx.xx.x.xxxxx

(很多 . 分割的字符串)
tiaoci 2006-05-12
  • 打赏
  • 举报
回复
是不是要加上单引号?

string sel="select * from 人员登陆参数表 where sno='" +TextBox1 + "'";


jimu8130 2006-05-12
  • 打赏
  • 举报
回复
dataset或者datareader都是数据容器,没关系只不过,datareader限制多些最主要就是只读
从你的代码可以看出来是你的sql语句构造错误,最后应该是TextBox1.Text.Trim()!
llwen218 2006-05-12
  • 打赏
  • 举报
回复
如果TextBox1是一个控件,则
string sel="select * from 人员登陆参数表 where sno=" +TextBox1.Text.ToString();
llwen218 2006-05-12
  • 打赏
  • 举报
回复
string sel="select * from 人员登陆参数表 where sno=" +TextBox1;
中的TextBox1是一个控件还是一个string类型的数据.
WeekZero 2006-05-12
  • 打赏
  • 举报
回复
string sel="select * from 人员登陆参数表 where sno=" +TextBox1;


TextBox1->TextBox1.Text

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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