Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
hi all!

i just want to know if it's possible to pass a datatable as sqlparameter, becasuse I do not want to use a for-each to insert row by row in my database

best regards!!

improving my question

i had not a particular problem, i just want to know if it's possible to do something like this

DataTable dt = new DataTable();
populateTable();
SqlConnection sqlConn = new SqlConnection(
    ConfigurationManager.ConnectionStrings["conString"].ConnectionString.ToString());
SqlCommand sqlCmd = sqlConn.CreateCommand();
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.CommandText = "myStoredProcedure";
sqlCmd.Parameters.Add("@Table", SqlDbType.Table).Value = dt;
sqlCmd.Connection.Open();
sqlCmd.ExecuteNonQuery();
sqlCmd.Connection.Close();
Posted
Updated 29-Feb-12 9:59am
v2

1 solution

The SqlParamater.SqlDBType cannot be set to a DataTable object.
See here[^]. You have to do rowbased updates.
 
Share this answer
 
Comments
MihaiPopescu 17-Jan-14 5:29am    
Check the Structured SqlDBType

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900