C#网页连接数据库的注册登录代码

vs是2010的数据库是sql2012的,代码最好前台后台的都有
2024-11-14 13:10:48
推荐回答(1个)
回答1:

using System.Data.SqlClient;

string strconn="server=(local);database=xwxt;uid=数据库用户名;pwd=数据库密码";
sqlconnection conn=new sqlconnection(strconn);
string str="select count(*) from denglu where username='"+txtuser.Text+"' and password='"+txtpassword.Text+"'";
SqlCommand cmd=new SqlCommand(str,conn);
conn.open;
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{ Response.Redirect("index.aspx");
}
else
{
Response.Write("");
}
conn.Close();