i am inserting some values in my table and at the same time, i want to call stored procedure that does some updates but i am having some issues with the syntax. I have searched online but could not find anything. I am just trying to figure out how can to use the same connection. here is my code:
sqlcmd.CommandText = "INSERT INTO MyTable(ID, Name ) VALUES(@ID, @Name)";
sqlcmd.Parameters.Clear();
sqlcmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = ID;
sqlcmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = Name;
sqlcmd.Connection = sqlcon;
sqlcmd.ExecuteNonQuery();
i saw some example on the internet but was not able to figure out how to use the same connection.
here is the example i found:
SqlCommand myCMD = new SqlCommand("sp_Test", sqlcon);
myCMD.CommandType = CommandType.StoredProcedure;
Code for executing procedure is like as follows
Must use Using which dispose as well as close connection