I am trying to send a DataTable to a stored procedure using C #,. Net 2.0 and SQLServer 2012 Express.
This is roughly what I am doing:
//define the DataTable var accountIdTable = new DataTable("[dbo].[TypeAccountIdTable]"); //define the column var dataColumn = new DataColumn {ColumnName = "[ID]", DataType = typeof (Guid)}; //add column to dataTable accountIdTable.Columns.Add(dataColumn); //feed it with the unique contact ids foreach (var uniqueId in uniqueIds) { accountIdTable.Rows.Add(uniqueId); } using (var sqlCmd = new SqlCommand()) { //define command details sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "[dbo].[msp_Get_Many_Profiles]"; sqlCmd.Connection = dbConn; //an open database connection //define parameter var sqlParam = new SqlParameter(); sqlParam.ParameterName = "@tvp_account_id_list"; sqlParam.SqlDbType = SqlDbType.Structured; sqlParam.Value = accountIdTable; //add parameter to command sqlCmd.Parameters.Add(sqlParam); //execute procedure rResult = sqlCmd.ExecuteReader(); //print results while (rResult.Read()) { PrintRowData(rResult); } }
But then I get the following error:
ArgumentOutOfRangeException: No mapping exists from SqlDbType Structured to a known DbType. Parameter name: SqlDbType
Upon further study (in MSDN, SO and other places) it looks as if .net 2.0 does not support sending DataTable to the database (such things are missing like SqlParameter.TypeName ), but I'm still not sure, since I have not seen so that anyone explicitly states that this feature is not available in .net 2.0
It's true?
If so, is there another way to send a collection of data to a database?
Thanks in advance!
source share