SQL Serverに対してユーザー名とパスワードを確認できる必要があり、C#フォームアプリケーション用のコードが必要です。C#フォームアプリケーションにSQL認証を追加するにはどうすればよいですか?
2つのテキストボックス(1ユーザーと1パス)でセットアップしてから、ログインボタンがあります。
SqlConnection UGIcon = new SqlConnection();
UGIcon.ConnectionString = "Data Source=HP-PC//localhost;Initial Catalog=UGI;Integrated Security=True";
UGIcon.Open();
string userText = textBox11.Text;
string passText = textBox12.Text;
SqlCommand cmd = new SqlCommand("SELECT stUsername,stPassword FROM LoginDetails WHERE stUsername='" + textBox11.Text + "' and stPassword='" + textBox12.Text + "'", UGIcon);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Login Success!!");
cmd = new SqlCommand("SELECT stRole from LoginDetails where [email protected]", UGIcon);
cmd.Parameters.AddWithValue("@stUsername",userText);
string role = cmd.ExecuteScalar().ToString();
MessageBox.Show(role);
UGIcon.Close();
}
else
{
MessageBox.Show("Access Denied!!");
UGIcon.Close();
}
にOnclickはのSQLConnectionとSqlCommandオブジェクトを作成し、あなたのDBを照会し、あなたが試してみました何のユーザ – f2lollpll
を読み、確認することができますSqlDataReaderのを取得しますか?だから、 "_I need for code for ... _"と言うのは一般に受け入れられない。私たちはあなたのためにあなたの仕事をするのではなく、あなたを助けるためにここにいます。 –
をopに追加しました。 –