-1
我寫了一個程序,應該從我的數據庫返回一個值。要返回的值是一個整數。這裏是我的代碼:過程返回錯誤:無法強制System.Int32 System.Int32 []
Private Sub btnSelectProducts_Click(sender As Object, e As EventArgs) Handles btnSelectProducts.Click
Try
'Connection Variables
Dim cnn As SqlCeConnection
Dim connectionString As String
'Connect to database
connectionString = "Data Source=|DataDirectory|\Database\ContactsAndInventory.sdf"
cnn = New SqlCeConnection(connectionString)
Dim Stream As New MemoryStream()
cnn.Open()
Dim command As New SqlCeCommand("SELECT CATEGORY_ID FROM PRODUCT_CATEGORY WHERE (CATEGORY_NAME = @CATEGORY_NAME)", cnn)
command.Parameters.AddWithValue("@CATEGORY_NAME", txtCategoryName.Text)
Dim catId As Integer() = CType(command.ExecuteScalar(), Integer())'Error Here
MsgBox(catId)
cnn.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
我收到錯誤:
System.InvalidCastException: Unable to cast objct to type System.Int32 to type System.Int32[]
在想不通爲什麼,現場是一個整場,我試圖返回的值是一個整數。我究竟做錯了什麼?
'昏暗CATID作爲整數()'是一個整數數組,的'()',它會工作離開。 – OneFineDay