private void button1_Click(object sender, EventArgs e)
{
string uname;
string upwd;
uname = textBox1.Text.ToString();
upwd = textBox2.Text;
int num=1;
int db;
db = getDB(uname, upwd);
if (num == db)
{
MessageBox.Show("全部成功", "好");
}
else
{
MessageBox.Show("NO", "好");
}
}
public static int getDB(string uname,string upwd)
{
SqlConnection con = new SqlConnection("server=XPSP2USER;uid=sa;pwd=sasa;database=demoDB");
con.Open();
string sql = "select * from utable where id='"+uname+"'and pwd='"+upwd+"'";
SqlCommand com = new SqlCommand(sql,con);
MessageBox.Show("数据库连接成功","好的");
int yz;
try
{
yz = Convert.ToInt16(com.ExecuteScalar());
}
catch(Exception e){
throw ;
}
con.Close();
return yz;
}
慕标5832272