KEY不能为null - VB.net错误

时间:2013-07-04 20:01:15

标签: mysql vb.net

伙计,我需要你的帮助。我有一个错误。请参阅下面的代码:

      Imports MySql.Data.MySqlClient
Public Class frmlogin
Dim conn As MySqlConnection = New MySqlConnection
Dim serverstring As String = "Server=localhost;User Id=root;Password=root;Database=dasystem"
Dim login As Boolean
Dim ds As DataSet
Dim cusds As DataSet
Dim da As MySqlDataAdapter
Dim dt As DataTable
Dim ctrshowlogin, ctrshowsearch As Integer


Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
    Dim rowctr As Integer
    Dim password As String
    ctrshowlogin = 0
    ds = New DataSet
    da = New MySqlDataAdapter("select * from password", conn)
    da.Fill(ds, "pword")

    If cmbuser.SelectedItem = "Administrator" Then
        For rowctr = 0 To ds.Tables(0).Rows.Count - 1
            password = ds.Tables(0).Rows(rowctr).Item(0).ToString
            If password = txtpass.Text Then
                login = True
            End If
        Next (rowctr)
        If login = True Then
            MessageBox.Show("Login Successful!")
            frmcomodities.Show()
            Me.Hide()
            cmbuser.Text = ""
        ElseIf login = False Then
            MessageBox.Show("Wrong Password, Please try again.")
            txtpass.Focus()
        End If
    End If
End Sub

Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles Cancel.Click
    Close()
End Sub
End Class

有什么想法吗?我遇到了这个问题。如果你能提供帮助,我很乐意欣赏它。感谢。

1 个答案:

答案 0 :(得分:0)

您需要更改da.Fill(ds, "pword")行中表的名称以匹配数据库表名(密码):

da.Fill(ds, "password")

或者只是完全删除该参数

da.Fill(ds)