0
我創建了一個帶有組合框的表單來搜索和4個文本框來查看字段值。我使用Form_load
事件來填充組合框。從類型LINQ結果到類型'整數'的轉換無效
這裏是我的代碼:
Imports System.Data.SqlClient
Imports System.Data.Linq
Public Class FRM_Product
Dim connection As New SqlConnection(connection string)
Dim db As New ProductDataContext(connection)
Private Sub FRM_ Product_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
Dim V_Query = db.Product_Write(Nothing, Nothing, Nothing, Nothing).ToList
If V_Query.Count <> 0 Then
CMB_Search.DataSource = V_Query
CMB_Search.ValueMember = "Product_ID"
CMB_Search.DisplayMember = "Product_A"
End If
End Sub
Private Sub CMB_Search_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CMB_Search.SelectedIndexChanged
Dim ID As Integer = CMB_Search.SelectedValue
Dim V_Query = db.Product_Write(Nothing, Nothing, Nothing, Nothing).ToList
TXT_Product_ID.Text = V_Query(0). Product_ID
TXT_ Product_A.Text = V_Query(0). Product_A
TXT_ Product_E.Text = V_Query(0). Product_E
TXT_ Product_NOTE.Text = V_Query(0). Product_Note
End Sub
而這裏的Product_Write
存儲過程:
CREATE PROCEDURE Product_Write
@ Product_ID INT = NULL ,
@ Product_A nvarchar(50)= NULL ,
@ Product_E nvarchar(50)= NULL ,
@ Product_Note nvarchar(255)= NULL
AS
BEGIN
SET NOCOUNT ON;
BEGIN
SELECT *
FROM [dbo].[ Product]
WHERE [Product_ID] = ISNULL(@Product_ID,[Product_ID])
AND [Product_A] = ISNULL(@Product_A,[Product_A])
AND [Product_E] = ISNULL(@Product_E, [Product_E])
ORDER BY [Product_A]
END
END
線
Dim ID As Integer = CMB_Search.SelectedValue
導致此錯誤:
Conversion from type ' Product_WriteResult' to type 'Integer' is not valid.'
如何解決此錯誤?
哪條線拋出該異常? – Fabio