1. string name=Request.Form["username"];
string pass=Request.Form["password"];
SqlConnection conn=new SqlConnection("server=服务器名字iis;uid=sa;pwd=123456;database=数据库名");
conn.Open();
string sql="select * from 表名";
SqlCommand myCommand= new SqlCommand(sql,conn);
SqlDataReader rstobj=myCommand.ExecuteReader();
try{
if(rstobj.Read()){
Response.Write("登陆成功");
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
finally
{
rstobj.Close();
conn.Close();
}
2.private void button1_Click(object sender, System.EventArgs e)
{
user_id = USER_ID.Text;
if(user_id == "")
{
MessageBox.Show("please input USER_ID");
return;
}
string user_pwd = USER_PWD.Text;
if(user_pwd == "")
{
MessageBox.Show("please input password");
return;
}
string strSQL;
strSQL = "SELECT * FROM A2_USER WHERE USER_ID = '" + user_id + "'";
SqlDataAdapter da = new SqlDataAdapter(strSQL, source);
DataSet ds = new DataSet();
da.Fill(ds,"USER");
try
{
if(ds.Tables["USER"].Rows.Count != 0)
{
if(ds.Tables["USER"].Rows[0]["USER_PWD"].ToString() == user_pwd.ToString())
{
this.Hide();
contract myForm = new contract();
myForm.ShowDialog();
this.Close();
}
else
{
MessageBox.Show("password is wrong,please enter correct password");
return;
}
}
else
{
MessageBox.Show("Not exist this user");
return;
}
}
catch(System.Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
}
}
3.private void loginqueding_Click(object sender, System.EventArgs e)
{
if(textBox2.Text==""||comboBox1.Text=="")
MessageBox.Show("用户名或密码为空!!");
else
{
try
{
string str="server=.;database=renshi;Integrated Security=True;";
SqlConnection con=new SqlConnection(str);
int res=0;
string pssd=textBox2.Text.ToString().Trim();
con.Open();
string cmdText="select * from userlist where name='"+username+"'and psd='"+pssd+"' ";
SqlCommand cmd=new SqlCommand();
cmd.CommandText=cmdText;
cmd.Connection=con;
SqlDataReader sqldr=null;
sqldr=cmd.ExecuteReader();
sqldr.Read();
string ss=sqldr["name"].ToString().Trim();
ppow=sqldr["qxian"].ToString().Trim();
pssd=sqldr["psd"].ToString().Trim();
//MessageBox.Show(pssd);
//ppow=tmppow;
if(ss==username)
res=1;
if(res==1)
{
this.Hide();
//Application.Exit();
Form1 f1=new Form1();
f1.tmppower=ppow;
f1.yuanmima=pssd;
f1.tmpname=ss;//name
f1.Show();
}
else
{
MessageBox.Show("code0err");
//textBox2.Text=res.ToString();
}
}
catch(Exception ex)
{
string nn=ex.Message.ToString();
//MessageBox.Show(nn);
MessageBox.Show("用户名或密码错误!!");
textBox2.Text="";
//comboBox1.Text="";
}
finally
{
//sqldr.Close();
//con.Close();
//MessageBox.Show(ppow);
}
}
}