public
void Main()
{
//buat datatable yang column-nya sama dengan struktur tvp
DataTable dt = new
DataTable();
dt.Columns.Add("name",System.Type.GetType("System.String"));
dt.Columns.Add("quantity",System.Type.GetType("System.Int32"));
dt.Columns.Add("errormessage",System.Type.GetType("System.String"));
//isi table dengan nilai yang ingin kita passing ke procedure
dt.Rows.Add("prod1", 100, DBNull.Value);
dt.Rows.Add("prod2", 200, DBNull.Value);
dt.Rows.Add("prod3", 0, DBNull.Value);
//connect ke database
SqlConnection connection = new
SqlConnection(Dts.Connections["localhost.Research"].ConnectionString);
connection.Open();
//execute InsertProduct dengan parameter dt
SqlCommand command = new
SqlCommand("InsertProduct", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@product", dt);
command.ExecuteNonQuery();
//tutup koneksi
connection.Close();
Dts.TaskResult = (int)ScriptResults.Success;
} |