How to pass table value parameters to stored procedure from .net code

DataTable, DbDataReader, or IEnumerable<SqlDataRecord> objects can be used to populate a table-valued parameter per the MSDN article Table-Valued Parameters in SQL Server 2008 (ADO.NET). The following example illustrates using either a DataTable or an IEnumerable<SqlDataRecord>: SQL Code: CREATE TABLE dbo.PageView ( PageViewID BIGINT NOT NULL CONSTRAINT pkPageView PRIMARY KEY CLUSTERED, PageViewCount BIGINT NOT NULL ); … Read more

An unhandled exception of type ‘System.InvalidOperationException’ occurred in System.Data.dll?

You should either use this method: SqlCommand cmd = new SqlCommand(“dbo.workScheduleDataGrid”, sqlcon); or this method SqlCommand cmd = sqlcon.CreateCommand(); to create the command, but not both (the second assignment in your code overwrites the first one). With the second options, you need to specify the command to execute separarely: cmd.CommandText = “dbo.workScheduleDataGrid”; Also, do not … Read more