VB.Net - ExecuteReader:CommandText属性尚未初始化

时间:2016-07-04 07:37:18

标签: sql vb.net executereader

我知道关于这个话题有一些线索,但由于某种原因,这些事情没有给我带来任何帮助。这就是我的代码:

Dim strAccSQL As String = "SELECT nUserNo FROM dbo.tUser WHERE sUserID='" & AccountID.Text & "';"
        Dim catCMDAcc As SqlCommand = New SqlCommand(strAccSQL, AccCon)
        Dim myAccountReader As SqlDataReader = catCMDAcc.ExecuteReader()
        While myAccountReader.Read
            AccountNo.Text = myAccountReader(0)
        End While
        myAccountReader.Close()
        Con.Close()
        Con.Open()
        Dim strSQL2 As String
        Dim catCMD As SqlCommand = New SqlCommand(strSQL2, Con)
        Dim myReader As SqlDataReader = catCMD.ExecuteReader()
        InfoTextBox.Text &= Environment.NewLine & Now & " Account: " & AccountID.Text & " Found"
        CharacterName.Properties.Items.Clear()
        While myReader.Read()
            CharacterName.Properties.Items.Add(myReader(0))
        End While
        myReader.Close()
        AccCon.Close()
        Con.Close()

有人对我的问题有所了解吗?

1 个答案:

答案 0 :(得分:0)

正如errormessage所述,你的CommandText在这里是空字符串(strSQL2):

   Dim strSQL2 As String
   Dim catCMD As SqlCommand = New SqlCommand(strSQL2, Con)
   Dim myReader As SqlDataReader = catCMD.ExecuteReader()

您无法执行空的sql子句。