2014-12-08 2 views
2

안녕하십니까. 로그인 창을 만들고 있습니다. (usingms vb 2008) SQL Server (2014)에서 데이터를 확인합니다. 잘못된 값을 주었을 때 else 블록이 실행되었습니다. 실행되지 않은 올바른 값을 제공합니다. 그 일을 할 수 있지만,if 블록 문을 실행할 수 없습니다.

Dim t As New TextBox 
Dim t1, t2 As New TextBox 
t.Text = ob.dr.Item("name").ToString 
t1.Text = ob.dr.Item("password").ToString 
t2.Text = ob.dr.Item("loger").ToString 

당신에게 이상한 오류가 발생하는 혼란과 책임입니다 :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

    If ((RadioButton1.Checked = False And RadioButton2.Checked = False) Or (TextBox1.Text = "" Or TextBox2.Text = "")) Then 
     MessageBox.Show("enter user name/password then select login as user/admin", "error", MessageBoxButtons.OK, MessageBoxIcon.Information) 
     TextBox1.Clear() 
     TextBox2.Clear() 
     RadioButton1.Checked = False 
     RadioButton2.Checked = False 
     TextBox1.Focus() 
    Else 
     If ((RadioButton1.Checked = True And RadioButton2.Checked = False) And (TextBox1.Text <> "" And TextBox2.Text <> "")) Then 
      Try 
       ob.connection() 
       Dim sql As String = "select * from password where loger='user0'" + "and (name=" + "'" + TextBox1.Text + "'" + "and password=" + "'" + TextBox2.Text + "')" 
       ob.Mydata(sql) 
       If ob.dr.Read() Then 
        Dim t, t1, t2 As New TextBox 
        t.Text = ob.dr.Item("name").ToString 
        t1.Text = ob.dr.Item("password").ToString 
        t2.Text = ob.dr.Item("loger").ToString 
        If (TextBox1.Text = t.Text And TextBox2.Text = t1.Text) Then 
         MessageBox.Show("successfully login", "login", MessageBoxButtons.OK, MessageBoxIcon.Information) 
         ' TextBox1.Text = "" 
         TextBox2.Text = "" 
         main.Show() 


         Me.Hide() 
        End If 
       Else 
        MessageBox.Show(" invalid userid/password.........", "log in error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
        TextBox1.Clear() 
        TextBox2.Clear() 
        RadioButton2.Checked = False 
        TextBox1.Focus() 
       End If 
      Catch ex As Exception '' getting Sql exception 
       MessageBox.Show(ex.Message.ToString()) 
      Finally 
       ob.connection_close() 
      End Try 
     Else 
      If ((RadioButton2.Checked = True And RadioButton1.Checked = False) And (TextBox1.Text <> "" And TextBox2.Text <> "")) Then 
       Try 
        ob.connection() 
        Dim sql As String = "select * from password where loger='admin'" + "and (name=" + "'" + TextBox1.Text + "'" + "and password=" + "'" + TextBox2.Text + "')" 
        ob.Mydata(sql) 
        If ob.dr.Read() Then 
         Dim t As New TextBox 
         Dim t1, t2 As New TextBox 
         t.Text = ob.dr.Item("name").ToString 
         t1.Text = ob.dr.Item("password").ToString 
         t2.Text = ob.dr.Item("loger").ToString 
         If (TextBox1.Text = t.Text And TextBox2.Text = t1.Text) And RadioButton2.Text = t2.Text Then 
          MessageBox.Show("successfully login", "login", MessageBoxButtons.OK, MessageBoxIcon.Information) 
          'TextBox1.Text = "" 
          TextBox2.Text = "" 
          main.Show() 

          Me.Hide() 
         End If 
        Else 
         MessageBox.Show(" invalid userid/password......", "login error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
         TextBox1.Clear() 
         TextBox2.Clear() 
         RadioButton2.Checked = False 
         TextBox1.Focus() 
        End If 
       Catch ex As Exception '' getting Sql exception 
        MessageBox.Show(ex.Message.ToString()) 
       Finally 
        ob.connection_close() 
       End Try 
      End If 
     End If 
    End If 
End Sub 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

End Sub 

최종 클래스

+0

정확히 어떤 행이 실행되고 있지 않습니까? –

+0

SQL 쿼리를 연결하지 않고 매개 변수를 사용하십시오. 암호에 '오류가 있습니다. 또한 쿼리에서 특정 비밀번호 (해쉬가 아닌!)가있는 특정 사용자를 확인하면 if 문에서 다시 확인해야하는 항목이 표시되지 않습니다. –

+0

IF 문에 중단 점을 넣습니다. 변수의 값을 확인하는 단일 단계입니다. –

답변

0

해결하기 위해 가장 먼저하는 일이있다. 대신 문자열을 사용하여 값을 저장하십시오.

Dim t As String 
Dim t1, t2 As String 
t = ob.dr.Item("name").ToString 
t1 = ob.dr.Item("password").ToString 
t2 = ob.dr.Item("loger").ToString 
+0

님이 제안한 바와 같이 위와 같이 선언했지만 문제가 해결되지 않았습니다. –

+0

올바른 항목이 만들어지면 실행되지 않은 행입니다. If (TextBox1.Text = t.Text 및 TextBox2.Text = t1.Text) Then MessageBox .Show 'TextBox1.Text = "" TextBox2.Text = "" main.Show() Me.Hide을 ((MessageBoxButtons.OK, MessageBoxIcon.Information "로그인", "성공적으로 로그인")) End If –

+0

중단 점을 설정하고 코드를 단계별로 실행하는 방법을 알고 있습니까? –

관련 문제