十万火急,求救!!!最好能留下qq。万分感激! 在将 varchar 值 'System.Web.UI.WebControls.TextBox' 转

protectedvoidImageButton1_Click(objectsender,ImageClickEventArgse){stringname=this.us... protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string name = this.usrname.Text.Trim();
string pwd = this.password.Text.Trim();

string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
string sqlStr = string.Format(" select COUNT(*) from admin1 where name1='{0}' and password1='{1}'", name, password);
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = new SqlCommand(sqlStr, conn);
int n = Convert.ToInt32(cmd.ExecuteScalar());

if (n > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "",
"<script> location.href = 'shouye.aspx'</script>"

);

}
else
{
ClientScript.RegisterStartupScript(

this.GetType(), "", "<script>alert('用户名或密码错误!')</script>"

);

}

小弟在‘登录‘按钮中实现的验证数据库账户密码的功能,基本代码应该没什么问题,运行时出现
!!!在将 varchar 值 'System.Web.UI.WebControls.TextBox' 转换成数据类型 int 时失败。,数据库中name和pasword类型是char(10)和int。。不知道问题在哪,求帮助,不胜感激!!!
展开
 我来答
蓝黑波涛CT974
2012-05-06 · 超过19用户采纳过TA的回答
知道答主
回答量:90
采纳率:0%
帮助的人:54.3万
展开全部
string name = this.usrname.Text.Trim();
----string pwd = this.password.Text.Trim();name和pasword类型是char(10)和int---
你获取密码类型就是string,而你数据表里面的是int当然错了!
你要么去该表的字段类型。
要么把获取的pass值转换成整形
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
tz6060996
2012-05-06 · TA获得超过2283个赞
知道大有可为答主
回答量:1171
采纳率:100%
帮助的人:1630万
展开全部
pasword是int的话, string sqlStr = string.Format(" select COUNT(*) from admin1 where name1='{0}' and password1='{1}'", name, password);
上面这句就有问题,需要把password1='{1}'"两边的单引号去掉,写成:
string sqlStr = string.Format(" select COUNT(*) from admin1 where name1='{0}' and password1={1}", name, password);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
果琴音016
2012-05-06 · 超过13用户采纳过TA的回答
知道答主
回答量:43
采纳率:0%
帮助的人:26.5万
展开全部
char类型的10个是固定的10个数字, 也就是说,你输入1个它还是10个。 。 你用varchar类型的试试
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
寄意寒星1234
2012-05-06 · 超过15用户采纳过TA的回答
知道答主
回答量:34
采纳率:0%
帮助的人:39.2万
展开全部
469629140 加
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式