您好,登錄后才能下訂單哦!
String userName = textBox1.Text;//用戶名
String userPw = textBox2.Text;//密碼
string connString = @"Data Source=ASUS\SQLEXPRESS;Initial Catalog=StudentScore;Integrated Security=True";
SqlConnection conn = new SqlConnection(connString);
string sql = String.Format("select count(*) from [user] where UserName='{0}'and Password='{1}'", userName, userPw);
try
{
conn.Open();// 打開數(shù)據(jù)庫連接
SqlCommand comm = new SqlCommand(sql, conn); //創(chuàng)建 Command 對象
int n = (int)comm.ExecuteScalar();//執(zhí)行查詢語句,返回匹配的行數(shù)
if (n==1)
{
Console.WriteLine("----->" + userName + " " + userPw + "登陸成功");
this.DialogResult = DialogResult.OK;
this.Tag = true;
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
else
{
MessageBox.Show("用戶名或者密碼錯誤", "登錄失敗",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.Tag = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "操作數(shù)據(jù)庫出錯!",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.Tag = false;
}
finally
{
conn.Close(); // 關(guān)閉數(shù)據(jù)庫連接
}
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。