using System.Data.SqlClient;
//连接数据库
SqlConnection scon = new SqlConnection("Server=.;database=Xk;integrated security=true");
//打开连接
scon.Open();
//将要执行的SQL语句
String str = String.Format("select count(*) from student where stuname='{0}' and pwd={1}", TextBox1.Text.Trim(), TextBox2.Text.Trim());
//执行SQL语句
SqlCommand cmd = new SqlCommand(str, scon);
//返回结果集中第一行第一列的值
int i =(int)(cmd.ExecuteScalar());
//判断返回值,若有返回值,对登录成功,否则,登录失败
if (i >= 1)
{
Response.Write("恭喜,登录成功");
}
else
{
Response.Write("对不起,没用此用户,登录失败!");
}
注意:database=Xk中,Xk是当前数据库库名,这个库名需要根据实际情况进行更改
字符串str中的数据表也是需要更改的
数据表student: