{
string s = "DATABASE=passkeySERVER=localhostIntegrated Security=True"
sql1 = new SqlConnection(s)
string a = "SELECT * FROM login"
adapter = new SqlDataAdapter(a, sql1)
ds = new DataSet()
adapter.Fill(ds,"LoginTemp")
for (int i = 0i <ds.Tables["LoginTemp"].Rows.Counti++)
{
if (textBox1.Text == (Convert.ToString(ds.Tables["LoginTemp"].Rows[i]["Username"]).Trim()) &&textbox2.Text == (Convert.ToString(ds.Tables["LoginTemp"].Rows[i]["Password"]).Trim()))
{
// button1.Text = "登陆成功"
this.DialogResult = DialogResult.OK
break
}
else
{
button1.Text = "登陆失败,请重新输入!"
continue
}
}
}
这是页面的代码。数据库链接的代码不在这里,在它背后的.cs文件里,或者在vs里的数据库资源管理器,然后在设计视图里绑定到表上。
帮你找了一点资料,你仔细看一下就明白了。
protected void btnQuery_Click(object sender, EventArgs e){
string str = "Data Source=.Initial Catalog=lianxiIntegrated Security=True"
SqlConnection conn = new SqlConnection(str)
int count = 0
try
{
conn.Open()
string sql = "select count (*) from UserForm where UserName=@username and UserPassWord=@userpassword"
SqlCommand cmd = new SqlCommand(sql, conn)
cmd.Parameters.Add(new SqlParameter("@username", this.tbUserName.Text))
cmd.Parameters.Add(new SqlParameter("@userpassword", this.tbUserPassWord.Text))
count = (int)cmd.ExecuteScalar()
}
catch (Exception ex)
{
Response.Write(ex.Message)
}
finally
{
conn.Close()
}
if (count >0)
{
Response.Write("<script>alert('登陆成功!')</script>")
}
else
{
Response.Write("<script>alert('登陆失败!')</script>")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)