ConnectionClass objconn
=
new
ConnectionClass();
//
实例化一个连接类
SqlConnection logConn = objconn.GetConnection();
DataSet logDs = new DataSet(); // 实例化一个数据集
try
... ... {
SqlCommand logCmd = logConn.CreateCommand(); //定义命令变量
logCmd.CommandType = CommandType.StoredProcedure;//指定命令变量的类型
logCmd.CommandText = "LoginProc";//指定命令变量的执行语句为存储过程名
logCmd.Parameters.Add(new SqlParameter("@Id", txtId.Text.Trim().ToString()));//添加参数
logCmd.Parameters.Add(new SqlParameter("@pwd", txtPassword.Text.Trim().GetHashCode().ToString()));//添加参数
//注意:参数名 和个数必须与存储过程的参数一样
SqlDataAdapter logSda = new SqlDataAdapter(logCmd);//定义适配器
logSda.Fill(logDs, "userinfo");//填充适配器
if (logDs.Tables["userinfo"].Rows.Count > 0)
......{
string objui="";
objui=txtId.Text.Trim().ToString();
Session.Add("wid",objui);//写入Session
//Response.Write("<script language='JavaScript'>alert('用户名、密码 正确 !')</script>");
Response.Redirect("mainFrame/mainframe.htm" ); //转向页面
}
else
......{
Response.Write("<script language='JavaScript'>alert('用户不存在 或 密码不正确 !')</script>");
return;
}
}
catch (Exception ex)
... ... {
Response.Write("<script language='JavaScript'>alert('登录失败 !')</script>");
return;
}
finally
... ... {
logConn.Close();//断开连接
}
SqlConnection logConn = objconn.GetConnection();
DataSet logDs = new DataSet(); // 实例化一个数据集
try
... ... {
SqlCommand logCmd = logConn.CreateCommand(); //定义命令变量
logCmd.CommandType = CommandType.StoredProcedure;//指定命令变量的类型
logCmd.CommandText = "LoginProc";//指定命令变量的执行语句为存储过程名
logCmd.Parameters.Add(new SqlParameter("@Id", txtId.Text.Trim().ToString()));//添加参数
logCmd.Parameters.Add(new SqlParameter("@pwd", txtPassword.Text.Trim().GetHashCode().ToString()));//添加参数
//注意:参数名 和个数必须与存储过程的参数一样
SqlDataAdapter logSda = new SqlDataAdapter(logCmd);//定义适配器
logSda.Fill(logDs, "userinfo");//填充适配器
if (logDs.Tables["userinfo"].Rows.Count > 0)
......{
string objui="";
objui=txtId.Text.Trim().ToString();
Session.Add("wid",objui);//写入Session
//Response.Write("<script language='JavaScript'>alert('用户名、密码 正确 !')</script>");
Response.Redirect("mainFrame/mainframe.htm" ); //转向页面
}
else
......{
Response.Write("<script language='JavaScript'>alert('用户不存在 或 密码不正确 !')</script>");
return;
}
}
catch (Exception ex)
... ... {
Response.Write("<script language='JavaScript'>alert('登录失败 !')</script>");
return;
}
finally
... ... {
logConn.Close();//断开连接
}