我是SQL Server中的新手,并尝试了解基础知识。我在SQL Express中的Northwind数据库中创建了一个示例TVP。我的VB.NET代码非常简单(见下文)。过程中TVP参数为空。我在SQL Server中测试了TVP,它运行正常。有任何想法吗? SQL Express是否完全支持表值参数?
Dim dt As DataTable = New DataTable()
dt.Columns.Add("RegionID", GetType(Int64))
dt.Columns.Add("RegionDesc", GetType(String))
dt.Rows.Add(21, "FromProgram2")
dt.Rows.Add(22, "FromProgram3")
Try
If dt.Rows.Count > 0 Then
Dim mycommand As SqlCommand = New SqlCommand
Dim myconn As SqlConnection = New SqlConnection(connstring)
mycommand.CommandText = "dbo.TestType"
mycommand.Connection = myconn
Dim param1 As SqlParameter = mycommand.Parameters.AddWithValue("@RegionData", dt)
param1.SqlDbType = SqlDbType.Structured
param1.TypeName = "dbo.RegionType"
mycommand.Connection.Open()
mycommand.ExecuteNonQuery()
mycommand.Connection.Close()
Console.WriteLine("")
Console.ReadLine()
Else
Console.Write("No data in datatable")
Console.ReadLine()
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.ReadLine()
End Try
答案 0 :(得分:0)
问题解决了。这是我在家里的设置问题。