Breaking News
Loading...
07/03/2014

Sử dụng Table Value Parameter trong ADO.net SQL Server

// Assumes conn is an open SqlConnection object and ds is
// a DataSet with an Order and OrderDetails table
using(conn)
{
// Create the command object to call the stored procedure
SqlCommand cmd = new SqlCommand("uspInsertNewOrder", conn);
cmd.CommandType = CommandType.StoredProcedure;
// Create the parameter for passing the Order TVP
SqlParameter headerParam = cmd.Parameters.AddWithValue
("@OrderHeaderTvp", ds.Tables["OrderHeader"]);
// Create the parameter for passing the OrderDetails TVP
SqlParameter detailsParam = cmd.Parameters.AddWithValue
("@OrderDetailsTvp", ds.Tables["OrderDetail"]);
// Set the SqlDbType of the parameters to Structured
headerParam.SqlDbType = SqlDbType.Structured;
detailsParam.SqlDbType = SqlDbType.Structured;
// Execute the stored procedure
cmd.ExecuteNonQuery();
}

0 comments:

Post a Comment

 
Toggle Footer