2014-02-19 76 views
-1

請幫助調試我的代碼。它是一個登錄表單,由於代碼中的錯誤而無法運行。請幫助我..我不知道如何調試它。
我是一名編程初學者。使用Vb.net和Mysql作爲數據庫登錄的代碼

Imports MySql.Data.MySqlClient 

Public Class Form1 

    ' Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     Dim cmd As New MySqlCommand 
     Dim da As New MySqlDataAdapter 
     Dim con As MySqlConnection = jokenconn() 
    End Sub' 

    Public Function jokenconn() As MySqlConnection 
     Return New MySqlConnection("server=localhost;user id=root;Database=db_ko;") 
    End Function 

    Private Sub cmdlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlogin.Click 
     Dim connString As String = "Database=db_ko;Data Source=localhost;User ID=root;" 

     Dim conn As New MySqlConnection(connString) 
     Dim cmd As New MySqlCommand 

     Dim user As String = txtusername.Text 
     Dim pass As String = txtpass.Text 
     Dim reader As DataTableReader 

     conn.Open() 
     cmd.CommandText = "SELECT * FROM `db_account` WHERE username= '" & txtusername.Text & "' and password= '" & txtpass.Text & "', conn" 
     cmd.Connection = conn 

     cmd.Parameters.Add(New MySqlParameter("?UserName", txtusername.Text)) 
     cmd.Parameters.Add(New MySqlParameter("?Password", txtpass.Text)) 

     cmd.Connection = conn 
     'cmd.EndExecuteReader = reader 

     If reader.HasRows() Then 
      MessageBox.Show("Login success!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information) 
      Form2.Show() 
      Me.Close() 

     Else 

      MsgBox("Invalid Login information.!", MessageBoxButtons.OK, MessageBoxIcon.Information) 
     End If 
     conn.Close() 

    End Sub 

End Class 

抱歉代碼錯誤。謝謝你提前!

+0

pakisabi nmn kung ano ung錯誤na lumalabas sa代碼mo:P ..我的意思是,c您請向我們展示您的代碼中的錯誤? – Codemunkeee

+0

yung ano po .. cmd.EndExecuteReader = reader。薩拉馬特波。 :D – anayaur30

+0

親愛的上帝。訪問數據庫的root用戶,sql注入問題和純文本密碼。脆弱代碼的三連勝。 –

回答

1

您已在此處註釋掉此行。刪除 「'」

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

,並更改爲

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

也嘗試刪除在該線上db_account的 「`」

cmd.CommandText = "SELECT * FROM `db_account` WHERE username= '" & txtusername.Text & "' and password= '" & txtpass.Text & "', conn" 

cmd.CommandText = "SELECT * FROM db_account WHERE username= '" & txtusername.Text & "' and password= '" & txtpass.Text & "', conn" 
+0

謝謝你po:D – anayaur30

+0

它的工作?同時避免使用tagalog語言,以便每個人都能理解。哈哈。玩得開心編碼! :) – Codemunkeee