SqlConnection sqlconn = new SqlConnection("Data Source=(local);Database=fhq_session:Uid=sa;Pwd=sa");
sqlconn.Open();
SqlCommand sqlcom = sqlconn.CreateCommand();
sqlcom.CommandText = "select count(*)from Region where name='"+TextBox1.Text+"'and pwd='"+TextBox2.Text+"'";
int count = Convert.ToInt32(sqlcom.ExecuteScalar());
if (count > 0)
{
Page.Response.Redirect("index_dlh.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名或密码不正确!');location='javascript:history.go(-1)'</script>");
这是个普通的验证登录框总 报错我代码哪里写错了吗??
sqlconn.Open();
SqlCommand sqlcom = sqlconn.CreateCommand();
sqlcom.CommandText = "select count(*)from Region where name='"+TextBox1.Text+"'and pwd='"+TextBox2.Text+"'";
int count = Convert.ToInt32(sqlcom.ExecuteScalar());
if (count > 0)
{
Page.Response.Redirect("index_dlh.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名或密码不正确!');location='javascript:history.go(-1)'</script>");
这是个普通的验证登录框总 报错我代码哪里写错了吗??
解决方案 »
- aspx页面静态化,哪种方法最简单
- ontextchange事件后台代码没有被执行
- Spring.net+NHibernate+asp.net mvc 问题求教!
- 求求你们救救我吧!RowDataBound的问题!求求你们了!~~~~~~
- datagrid中数据输出格式
- 怪事 做的后台程序 有的能运行有的不能用 不同的机器都不同 急-----------!!!!!!!!!!
- 如何完全删除一个项目?
- 关于web.config
- 急!!!!在线求救,解决即散分。
- 请问在网页对话框中如何使ASPX不打开另一个窗口?
- 如何MVC Filter实现跳转,并提供一些学习资料
- c# web开发sql注入问题?
sqlcom.ExecuteScalar()里面返回的是什么
报的就是这个错误!!!
证明 数据库连接不上. 仔细检查下配置.
sqlconn.Open();
SqlCommand sqlcom = sqlconn.CreateCommand();
sqlcom.CommandText = "select count(*)from Region where name='"+TextBox1.Text+"'and pwd='"+TextBox2.Text+"'"; /* ExecuteScalar()返回的是首行首列
int count = Convert.ToInt32(sqlcom.ExecuteScalar());
if (count > 0)
{
Page.Response.Redirect("index_dlh.aspx");
}
else
{
Response.Write(" <script lanuage=javascript>alert('用户名或密码不正确!');location='javascript:history.go(-1)' </script>");
}
*/ SqlDataReader sdr= cmd.ExecuteReader(); if(sdr.Read())
{
sdr.Close();
Page.Response.Redirect("index_dlh.aspx");
}
else
{
sdr.Close();
Response.Write(" <script lanuage=javascript>alert('用户名或密码不正确!');location='javascript:history.go(-1)' </script>");
}
sqlconn.Open();
SqlCommand sqlcom = sqlconn.CreateCommand();
sqlcom.CommandText = "select count(*)from Region where name='"+TextBox1.Text+"'and pwd='"+TextBox2.Text+"'"; /* ExecuteScalar()返回的是首行首列
int count = Convert.ToInt32(sqlcom.ExecuteScalar());
if (count > 0)
{
Page.Response.Redirect("index_dlh.aspx");
}
else
{
Response.Write(" <script lanuage=javascript>alert('用户名或密码不正确!');location='javascript:history.go(-1)' </script>");
}
*/ SqlDataReader sdr= sqlcom.ExecuteReader(); if(sdr.Read())
{
sdr.Close();
Page.Response.Redirect("index_dlh.aspx");
}
else
{
sdr.Close();
Response.Write(" <script lanuage=javascript>alert('用户名或密码不正确!');location='javascript:history.go(-1)' </script>");
} 试试,或许能用
换成下面的试试:
SqlConnection sqlconn = new SqlConnection("server=.\sqlexpress;user=sa;pwd=sa;database=fhq_session");
SqlConnection sqlconn = new SqlConnection("Server=(local);Database=fhq_session:Uid=sa;Pwd=sa");
string sql="select count(*)from Region where name='"+TextBox1.Text+"'and pwd='"+TextBox2.Text+"'";
SqlCommand sqlcom = new SqlCommand(sql,sqlconn);
sqlconn.Open();
int count = (int)sqlcom.ExecuteScalar();
if (count > 0)
{
Page.Response.Redirect("index_dlh.aspx");
}
else
{
Response.Write(" <script lanuage=javascript>alert('用户名或密码不正确!');location='javascript:history.go(-1)' </script>");
我想这样的话是可以解决的可能的话。 int count = (int)sqlcom.ExecuteScalar();
这句话可能会出错那是因为数据库字段的类型转换有问题
http://www.it63.net一起去学习学习