0

我究竟做错了什么?我已经这样做了一段时间了……我投降了。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Using sqlCon = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\gadgetDatabase.mdf;Integrated Security=True")

        Dim Id As Integer = 2
        'With the use of ID, it will get the appName or Application Display Name
        sqlCon.Open()
        Dim sqlText = "SELECT appName " & _
                      "FROM appTable " & _
                      "WHERE Id = @sqlID"
        Dim sqlCmd = New SqlCommand(sqlText, sqlCon)
        sqlCmd.Parameters.AddWithValue("@sqlID", Id)
        'sqlCmd.ToString()
        sqlCmd.ExecuteScalar() 'I had these in there before I copied the code over
        sqlCon.Close()
        Label3.Text = sqlText 'For testing or confirmation it went correctly...

    End Using

End Sub
4

1 回答 1

1

You forgot to call

string apName = sqlCmd.ExecuteScaler();

and retrieve the result.

If a resultset (multiple results) is expected, then call reader = cmd.ExecuteReader() and loop through the results.

于 2013-04-21T04:06:14.667 回答