关于登陆界面连接数据库的问题
我做了一个登陆界面,大概就是下面的这样:用户名:
密码:
登录 取消
还有用sql数据库建立了一个表,login.mdf,怎么才能把两者连接起来?
很急,在线等! --------------------编程问答-------------------- 看书....... --------------------编程问答-------------------- //using System.Data;
//using System.Data.SqlClient;
using (SqlConnection cn = new SqlConnection(%%1))
//ConfigurationManager.ConnectionStrings["db2ConnectionString"].ConnectionString
//Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
{
SqlCommand cmd = new SqlCommand("Select Count(*) From jobs",cn);
cn.Open();
%%2=cmd.ExecuteScalar(); //Message.InnerHtml
if(%%2==%%3)
{
%%4
}
--------------------编程问答-------------------- 这个问题问的。。。
1,配置链接字符串
2,使用ado.net进行数据库的操作
3,根据操作结果来执行逻辑 --------------------编程问答-------------------- protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.\\SQLEXPRESS;Integrated Security=True;Connect Timeout=30;User Instance=True;AttachDbFilename=" + Server.MapPath("\\***\\App_Data\\login.mdf");//你数据库的地址
conn.Open();
SqlCommand cmd = new SqlCommand();
string username = this.username.Text;
string pwd = this.password.Text;
cmd.CommandText = "select * from tbuser where username='" + username + "'and password='" + pwd + "'";
cmd.Connection = conn;
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
Session["username"] = username;
sdr.Close();
conn.Close();
Response.Write("<script>alert('恭喜你,登陆成功!');window.location.href='news/Default.aspx';</script>");
}
else
{
sdr.Close();
conn.Close();
Response.Write("<script>alert('登陆失败,请确认您的用户名和密码!');window.location=window.location;</script>");
//Response.Write("用户名或密码错误!");
//Response.Redirect("login.aspx");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
this.username.Text = "";
this.password.Text = "";
}
补充:.NET技术 , C#