Hello,
I have created a stored procedures with 2 where criteria. How can i pass two parameters to a stored procedure as criteria from c# coding?
Thank you in advance.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Roei BarRank #1,271 · 1.4K reputationPosted Sep 13, 2009, 12:17 AM EDT
well there are 2 options which i will show in the following code sample:
using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(commandText, connection); // in this whay we need to declare the SQLDBType in // advance command.Parameters.Add("@ID", SqlDbType.Int); command.Parameters["@ID"].Value = customerID; // Use AddWithValue to assign Demographics. // SQL Server will implicitly convert strings into XML. command.Parameters.AddWithValue("@demographics", demoXml); try { connection.Open(); Int32 rowsAffected = command.ExecuteNonQuery(); Console.WriteLine("RowsAffected: {0}", rowsAffected); } catch (Exception ex) { Console.WriteLine(ex.Message); }DealyRank #9,518 · 205 reputationPosted Sep 13, 2009, 12:23 AM EDT
So, with your code i pass @parameters ID and @demographics into my stored procedure?
And if i want to pass more than 2 i just add this line of code with the variables i need? command.Parameters.AddWithValue("@demographics", demoXml);Roei BarRank #1,271 · 1.4K reputationPosted Sep 13, 2009, 12:28 AM EDT
command.Parameters.AddWithValue("@demographics", demoXml); command.Parameters.AddWithValue("@demographics2", demoXml); command.Parameters.AddWithValue("@demographics3", demoXml); means that you have 3 parameters in your SP in that order :@demographics Xml,@demographics2 Xml,@demographics3 XmlDealyRank #9,518 · 205 reputationPosted Sep 13, 2009, 12:31 AM EDT
No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type.
DealyRank #9,518 · 205 reputationPosted Sep 13, 2009, 12:33 AM EDT
Thanks for all the help :)