protected void Button1_Click2(object sender, EventArgs e)
{
Session["UserID"] = txtUserID.Text;
Session["UserName"] = txtUserName.Text; DataCon myCon = new DataCon();
SqlConnection sqlconn = myCon.getCon();
sqlconn.Open();
if (AdminChk1.Checked==true)
{
string str = "select count(*) from tb_Admin where AdminID='" + txtUserID.Text + "'and AdminName='" + txtUserName + "' and AdminPwd='" + txtPsw.Text + "' ";
SqlCommand sqlcom = new SqlCommand(str, sqlconn);
int count=Convert.ToInt32(sqlcom.ExecuteNonQuery()); if(count>0)
{
Page.Response.Redirect("AdminMain.aspx");
}
else
{
Response.Write("<script> window.alert('登陆失败!') </script>");
}
} else
{
string str = "select count(*) from tb_User where UserID='" + txtUserID.Text + "'and UserName='" + txtUserName.Text + "'and UserPwd='" + txtPsw.Text + "'";
SqlCommand sqlcom = new SqlCommand(str, sqlconn);
int count=Convert.ToInt32(sqlcom.ExecuteNonQuery()); if(count>0)
{
Response.Redirect("UserMain.aspx");
}
else
{ Response.Write("<script> window.alert('登陆失败!') </script>");
}
}
sqlconn.Close(); }
我谢了一个DataCon类 ,用来连接数据库的:代码如下public DataCon()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public SqlConnection getCon()
{
string sqlCon = "Data Source=(local);Initial Catalog=db_BBS;Integrated Security=True";
SqlConnection mycon = new SqlConnection(sqlCon);
return mycon;
}
运行那个代码之后输入的用户名正确的情况下也显示登录失败,不知道是什么原因,请各位指教一下
{
Session["UserID"] = txtUserID.Text;
Session["UserName"] = txtUserName.Text; DataCon myCon = new DataCon();
SqlConnection sqlconn = myCon.getCon();
sqlconn.Open();
if (AdminChk1.Checked==true)
{
string str = "select count(*) from tb_Admin where AdminID='" + txtUserID.Text + "'and AdminName='" + txtUserName + "' and AdminPwd='" + txtPsw.Text + "' ";
SqlCommand sqlcom = new SqlCommand(str, sqlconn);
int count=Convert.ToInt32(sqlcom.ExecuteNonQuery()); if(count>0)
{
Page.Response.Redirect("AdminMain.aspx");
}
else
{
Response.Write("<script> window.alert('登陆失败!') </script>");
}
} else
{
string str = "select count(*) from tb_User where UserID='" + txtUserID.Text + "'and UserName='" + txtUserName.Text + "'and UserPwd='" + txtPsw.Text + "'";
SqlCommand sqlcom = new SqlCommand(str, sqlconn);
int count=Convert.ToInt32(sqlcom.ExecuteNonQuery()); if(count>0)
{
Response.Redirect("UserMain.aspx");
}
else
{ Response.Write("<script> window.alert('登陆失败!') </script>");
}
}
sqlconn.Close(); }
我谢了一个DataCon类 ,用来连接数据库的:代码如下public DataCon()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public SqlConnection getCon()
{
string sqlCon = "Data Source=(local);Initial Catalog=db_BBS;Integrated Security=True";
SqlConnection mycon = new SqlConnection(sqlCon);
return mycon;
}
运行那个代码之后输入的用户名正确的情况下也显示登录失败,不知道是什么原因,请各位指教一下
解决方案 »
- C# PictureBox自适应尺寸
- reportView不显示报表数据,但在gridView中显示.
- gridview导出pdf文件 中文字体不显示的问题
- 报表问题,Vs2005,IE7显示不全,求救各位大虾了
- C# windows编程SQL Server 2005 数据库连接
- 进程之间怎么通信????
- ★★★★★究竟谁是垃圾,CSDN有史以来最有影响力的两大高手开始辩论★★★★★--上海交大的migthline和亡灵法师alienbat
- 如何根据cell不同的内容确定ColumnType?
- 最近遇到一个难题了,想用TreeView展示二叉树形式树
- 如何绑定 ?
- 有关连接数据库的问题。
- 自定义控件放何容器?
单步 跟踪结果