【问题标题】:Vb and MySQL connection and code errorsVB与MySQL连接及代码错误
【发布时间】:2013-11-21 05:51:14
【问题描述】:

大家好,我又卡住了,当表单加载时,我收到错误:“连接错误:位置 0 处没有行”帮助!?

 Private Sub frmadduser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim sqlDT As New DataTable
    txtlname.Text = ""
    txtfname.Text = ""
    txtaddress.Text = ""
    txtcontact.Text = ""
    Try
        If Me.Text = "Edit Account" Then
            sqlSTR = "SELECT * FROM users WHERE idUsers =" & FrmSYSUSER.lstusers.FocusedItem.Text
            ExecuteSQLQuery(sqlSTR)
            MsgBox(sqlDT.Rows(0)("Username"))
            With sqlDT
                If .Rows.Count > 0 Then
                    txtlname.Text = .Rows(0)("lname")
                    txtfname.Text = .Rows(0)("fname")
                    txtaddress.Text = .Rows(0)("address")
                    txtcontact.Text = .Rows(0)("contact")
                    txtusername.Text = .Rows(0)("username")
                    txtpassword.Text = .Rows(0)("password")
                    txtconfirm.Text = .Rows(0)("password")
                    cmbaccnttype.Text = .Rows(0)("accesstype")
                End If
            End With
        End If
    Catch ex As Exception
        MsgBox("Connection Error :" & ex.Message, MsgBoxStyle.Information, xTitlename)
    End Try
End Sub

【问题讨论】:

    标签: mysql vb.net visual-studio-2012


    【解决方案1】:

    如果你 ExecuteSQLQuery(sqlSTR) 返回一个 DataTable 你可能会这样做:

      sqlDT = ExecuteSQLQuery(sqlSTR)
    

    并在对其执行任何操作之前检查是否有行,例如:

     if (sqlDT.Rows.Count>0) Then
        With sqlDT
             txtlname.Text = .Rows(0)("lname")
             txtfname.Text = .Rows(0)("fname")
             txtaddress.Text = .Rows(0)("address")
             txtcontact.Text = .Rows(0)("contact")
             txtusername.Text = .Rows(0)("username")
             txtpassword.Text = .Rows(0)("password")
             txtconfirm.Text = .Rows(0)("password")
             cmbaccnttype.Text = .Rows(0)("accesstype")
        End With
     End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-13
      • 2021-07-29
      • 2016-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多