VB:
'To represent the table parameter in C#, we need to either
'have a set of entities which are IEnumreable
'or a data reader or a Data table.
'In this example we create a data table with same name as the type we have in the DB
Dim dataTable As System.Data.DataTable = New System.Data.DataTable("SampleDataType")
'we create column names as per the type in DB
dataTable.Columns.Add("LocationName", GetType(String))
dataTable.Columns.Add("CostRate", GetType(Int32))
'and fill in some values
dataTable.Rows.Add("99", 99)
dataTable.Rows.Add("98", Nothing)
dataTable.Rows.Add("97", 99)
Dim conn As New Data.SqlClient.SqlConnection
Dim cmd As New Data.SqlClient.SqlCommand
If conn.State = Data.ConnectionState.Open Then
conn.Close()
End If
conn.ConnectionString = "Integrated Security=SSPI;Persist Security Info=True;Data Source=localhost;Packet Size=4096;Initial Catalog=AdventureWorks2008"
conn.Open()
Dim parameter As System.Data.SqlClient.SqlParameter = New System.Data.SqlClient.SqlParameter()
'The parameter for the SP must be of SqlDbType.Structured
parameter.ParameterName = "@TVP"
parameter.SqlDbType = System.Data.SqlDbType.Structured
parameter.Value = dataTable
With cmd
.Connection = conn
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "usp_InsertProductionLocation"
'.Parameters.Add(New Data.SqlClient.SqlParameter("@txta", Data.SqlDbType.VarChar, 10))
'.Parameters("@txta") = txta.text
'.Parameters.Add(New Data.SqlClient.SqlParameter("@txtb", Data.SqlDbType.VarChar, 10))
'.Parameters("@txtb") = txtb.text
.Parameters.Add(parameter)
grdDetail.DataSource = .ExecuteReader()
End With
'Dim daGetProducts As New Data.SqlClient.SqlDataAdapter(cmd)
'Dim dsProducts As New Data.DataSet()
'daGetProducts.Fill(dsProducts, "Products")
'grdDetail.DataSource = dsProducts
'GridView1.DataSource = dsProducts
'GridView1.DataBind()
grdDetail.DataBind()