-1
我創建表值參數是這樣的:操作數類型衝突:爲nvarchar是不相容,而使用TVP
CREATE TYPE dbo.ss AS TABLE(ss1 integer);
然後我寫存儲過程是這樣的:
ALTER PROCEDURE [dbo].[T_TransactionSummary]
@locations dbo.ss readonly
as
begin
...............
.............
AND (Location_tbl.Locid IN (select ss1 from @locations))
我LOCID字段是整數此locid來自我的listbox.if我選擇一個項目1 locid會come.if我選擇2項目2 locid會來..我有一個ListBox填充@locations參數(整數),我把我的列表框值這
cnt = LSTlocations.SelectedItems.Count
Dim dtlist As New DataTable()
Dim locid As Integer
If cnt > 0 Then
For i = 0 To cnt - 1
dtlist.Columns.Add(locid, GetType(Integer))
Dim locationanme As String = LSTlocations.SelectedItems(i).ToString
locid = RecordID("Locid", "Location_tbl", "LocName", locationanme)
dtlist.Rows.Add(locid)
Next
End If
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim cmd23 As New SqlCommand("T_TransactionSummary", con.connect)
cmd23.CommandType = CommandType.StoredProcedure
Dim tvp1 As SqlParameter = cmd23.Parameters.AddWithValue("@locations", dtlist)
tvp1.SqlDbType = SqlDbType.Structured
da.SelectCommand = cmd23
da.Fill(ds)
但我收到錯誤:試圖傳遞一個表值參數與2列(s)其中相應的用戶定義的表類型需要1列(s)。
sir ..in type i changed into int and code i changed to like this: cmd23.Parameters.Add(「@ locations」,SqlDbType.Int).Value = String.Join(「,」,list)但出現錯誤:無法將參數值從字符串轉換爲Int32。 – user2878851
我怎麼可以像一個datatable通過..你可以顯示一次 – user2878851
好吧,先生謝謝你的幫助..我會盡力找出 – user2878851