2012-03-10 2 views
0

나는 Visual Studio 2008을 사용하여 Windows 응용 프로그램을 만듭니다. 연결이 끊긴 방식으로 로그인 양식을 만들고 싶습니다. DataTable이 채워지는지 검사하려고 할 때 항상 채워지는 것을 보여주는 문제에 직면하고 있습니다. 로그인 버튼연결이 끊긴 구조의 로그인 양식 C#

코드 :

귀하의 오류가 체크에있다
try 
     { 
      //getting connectionString 
      mcc = new myConnectionClass(); 
      conString = mcc.MyConnection; 
      //opening connection con 
      con = new SqlConnection(conString); 
      string queryString = "select * from LOGIN_TABLE where LOGIN_ID = @LOGIN_ID and LOGIN_PASSWORD = @LOGIN_PASSWORD"; 
      //dataset ds , SqlDataAdapter sda 
      ds = new DataSet(); 
      sda = new SqlDataAdapter(); 
      //sqlcommand 
      cmd = new SqlCommand(queryString, con); 
      cmd.Parameters.Add(new SqlParameter("LOGIN_ID", txtLogin.Text)); 
      cmd.Parameters.Add(new SqlParameter("LOGIN_PASSWORD", txtPass.Text)); 
      sda.SelectCommand = cmd; 

      sda.Fill(ds, "LOGIN_TABLE"); 
      //datatable dt 
      dt = ds.Tables["LOGIN_TABLE"]; 
      //checking is datatable is empty 
      if (dt != null) 
      { 
       MessageBox.Show("Login Successed"); 
      } 
      else 
      {     
       MessageBox.Show("Login Failed"); 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
     finally 
     { 
      ds.Clear(); 
      dt.Clear(); 
     } 

답변

1

if(dt != null) 

에 대한 그것은 당신의 LOGIN_TABLE

당신의 번호를 확인할 필요가있는 경우에 allways 사실 행.

if(dt.Rows.Count != 0) 

보안상의 관점에서 보면 데이터베이스에 로그인 암호를 저장하는 것은 좋지 않습니다.

+0

헤이 뭔가 추가가 로그인과 암호를 저장하는 코드 –

+0

을하고있다 데이터를 저장하는 것이 좋은 생각이 아닙니다. –

+1

사용 유에게 적절한 가까이를 보장하고이 자원 – Steve

관련 문제