做一个ASP的登录:我一登录就说我抛出的=后有错误。求高手解决下。
这事数据访问层:
string sqlst = "Data Source=.;Initial Catalog=ContestDB;Integrated Security=True";
SqlConnection con = null;
public string sqlconn(string sql)
{
try
{
con = new SqlConnection(sqlst);
con.Open();
SqlCommand comm = new SqlCommand(sqlst, con);
string sqlscl = comm.ExecuteScalar().ToString();
con.Close();
return sqlscl;
}
catch
{
throw;
}
逻辑层:
public bool ii(string id, string pwd)
{
string sqls = "select count(*) from SF_userr where SF_ID='"+id+"' and SF_pwd='"+pwd+"'";
sqldbhelper sqldb = new sqldbhelper();
if (int.Parse(sqldb.sqlconn(sqls)) > 0)
{
return true;
}
else
{
return false;
}
UI层:
protected void Button1_Click(object sender, EventArgs e)
{
string Id = TextBox1.Text.Trim();
string Pwd = TextBox2.Text.Trim();
Ctrl_info infto = new Ctrl_info();
if (infto.ii(Id, Pwd))
{
Response.Write("<script>alert('成功')</script>");
}
else
{
Response.Write("<script>alert('失败')</script>");
}
这事数据访问层:
string sqlst = "Data Source=.;Initial Catalog=ContestDB;Integrated Security=True";
SqlConnection con = null;
public string sqlconn(string sql)
{
try
{
con = new SqlConnection(sqlst);
con.Open();
SqlCommand comm = new SqlCommand(sqlst, con);
string sqlscl = comm.ExecuteScalar().ToString();
con.Close();
return sqlscl;
}
catch
{
throw;
}
逻辑层:
public bool ii(string id, string pwd)
{
string sqls = "select count(*) from SF_userr where SF_ID='"+id+"' and SF_pwd='"+pwd+"'";
sqldbhelper sqldb = new sqldbhelper();
if (int.Parse(sqldb.sqlconn(sqls)) > 0)
{
return true;
}
else
{
return false;
}
UI层:
protected void Button1_Click(object sender, EventArgs e)
{
string Id = TextBox1.Text.Trim();
string Pwd = TextBox2.Text.Trim();
Ctrl_info infto = new Ctrl_info();
if (infto.ii(Id, Pwd))
{
Response.Write("<script>alert('成功')</script>");
}
else
{
Response.Write("<script>alert('失败')</script>");
}
题外话,你的dal貌似有问题,不过这个跟你的错误应该关系不大:
SqlConnection con = null;
public string sqlconn(string sql)
{
try
{
con = new SqlConnection(sqlst);con为什么要定义为实例级别的变量?临界情况下,当sqlconn出现并发操作的时候,你的con会被重复赋值,从而现异常.
当然,如果你确定自己必须使用实例级别的变量,那么对于这个变量的初始化你应该保证只会进行一次.