你好我正在創建一個登錄窗口 (usingms vb 2008),它檢查來自sql server(2014)的數據我的else塊被執行時我給出了任何錯誤的值,但是當我給它正確的價值它沒有被執行。無法執行if語句
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
末級
究竟哪一行沒有被執行? – 2014-12-08 07:40:20
不要連接你的sql查詢,使用參數。如果密碼包含'你將會有錯誤。另外,如果您的查詢使用特定密碼檢查特定用戶(而不是散列?!),那麼我在您的if語句中看不到需要再次檢查的內容。 – 2014-12-08 13:54:55
在您的IF語句中放置一個斷點,通過它驗證變量的值。 – 2014-12-08 14:32:27