I have a datatable fetching values from a stored procedure written as below:
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString);
sqlcon.Open();
DataTable dt = new DataTable("tmp");
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("usp_abc", sqlcon);
cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = cmd;
da.Fill(dt);
Now, I need to loop through the datatable and get the values of this datatable and pass it is as a parameter to my stored proc.
I believe such operation is better done in the DB if possible instead of going to the DB for each row in the datatable row collection.
You can use foreach to loop through the datatable, each
DataRowrepresenting a row in the returned result.You can throw more light on what you want to do if it’s possible to move it to DB (using stored procedure)
Update: Passing value to stored proc using
command.Parameters