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();
}
는 온 클릭은 SQLConnection을하고있는 SqlCommand을하고 DB를 조회 읽고 당신이 시도 무엇 사용자 – f2lollpll
을 확인할 수있는 SqlDataReader 개체를 얻을? 일반적으로 "_I 코드가 필요합니다 ..."라고 말하는 것은 용납되지 않습니다. 우리는 당신을 돕기 위해 당신을 위해 일하는 것이 아니라 당신을 돕기 위해 왔습니다. –
방금 op에 추가했습니다. –