用户代码未处理sqlexection 怎么解决啊?
用户代码未处理sqlexection 怎么解决啊?using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.Sql;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string user_name = Request.Form["user_name"].ToString();
string user_password = Request.Form["user_password"].ToString();
SqlConnection conn = new SqlConnection("server=.;pwd=;uid=sa;database=login;");
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from login where user_name='"+user_name+"'and user_password='"+user_password+"'",conn);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
Response.Redirect("main.aspx?user_name="+user_name);
}
else
{
Response.Redirect("loginFail.htm");
}
}
}
--------------------编程问答-------------------- 楼主应该看看真正出错的信息
就凭楼主所说,根本无法确认是连接出错还是执行语句出错
还有确认你的数据库和表名字都是login
SqlConnection conn = new SqlConnection("server=.;pwd=;uid=sa;database=login;");
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from login where user_name='"+user_name+"'and user_password='"+user_password+"'",conn);
==
即使是login,也该改为
SqlConnection conn = new SqlConnection("server=.;pwd=;uid=sa;database=[login]");
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from [login] where user_name='"+user_name+"'and user_password='"+user_password+"'",conn);
--------------------编程问答-------------------- 是数据库安装期间没有选择默认 --------------------编程问答-------------------- 加try..catch --------------------编程问答-------------------- 错误很可能是:
1.连接字符传出了问题
2.sql 语句写的有问题
---
建议单步调试,看看到底在哪里出错~ --------------------编程问答-------------------- 数据库名是LOGIN 表名也是LOGIN?
补充:.NET技术 , ASP.NET