IN .Net 2.0 C# Passing Datatable to Stored Prodedure Ocured Error

79 Views Asked by At

System.ArgumentException: No mapping exists from DbType {0} to a known {1}. at System.Data.SqlClient.MetaType.GetMetaType(Object value) at System.Data.SqlClient.SqlParameter.set_Value(Object value)

1

There are 1 best solutions below

3
On

When passing a DataTable from c# to SQL Server, make sure you have a User-Defined table type created. The data type and length of each column in the table type must match exactly the data types of each column in your data table in c#.

enter image description here

If you ere passing the table to a stored procedure as an input parameter, it can look something like this:

CREATE procedure [dbo].[usp_MyStoredProc]

@Var1 date,
@Var2 varchar(8),
@MyInputTable as dbo.MyUserDefinedTableType READONLY

AS

SET NOCOUNT ON;

-- Stored pcedure code ...