C # Call custom table type parameters
-Test environment generated by SQL SERVER:
-- CREATE test DBCREATE database Sales; goUSE SalesGO -- CREATE the table type if TYPE_ID ('localdt ') is not nulldrop type LocalDTGO create type LocalDT as table (id int not null, name NVARCHAR (50) GO -- create the stored procedure if OBJECT_ID ('P _ able ', 'P') is not nulldrop proc P_DataTable; gocreate procedure P_DataTable (@ LocalDT READONLY) ASSELECT * FROM @ LocalDTGO
-- Open Visual Studio-create a project-select console application]
Using System; using System. collections. generic; using System. linq; using System. text; using System. data; using System. data. sqlClient; namespace ProcDataTable {class Program {static void Main (string [] args) {DataTable dt = new DataTable ("LocalDT"); dt. columns. add ("ID", typeof (int); dt. columns. add ("Name", typeof (string); DataRow dr = dt. newRow (); dr [0] = 1; dr [1] = "Roy"; dt. rows. add (dr); SqlConnection thisConnection = new SqlConnection (@ "Server = Instance name; Database = Sales; User ID = sa; Password = 1"); thisConnection. open (); SqlCommand sqlcmd = thisConnection. createCommand (); sqlcmd. commandType = CommandType. storedProcedure; sqlcmd. commandText = "P_DataTable"; SqlParameter param = sqlcmd. parameters. addWithValue ("@ LocalDT", dt); SqlDataReader sdr = sqlcmd. executeReader (); while (sdr. read () {Console. writeLine ("ID: {0} \ tName: {1}", sdr [0], sdr [1]);} thisConnection. close (); Console. readKey ();}}}
-- Test Result: