ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Different way to pass parameter to command object in ASP.Net<p>These are the way to pass parameter to sql command.</p> <pre class="brush: csharp">using (SqlConnection conn = new SqlConnection(GetConnectionString()) { conn.Open(); SqlCommand cmd = new SqlCommand(query, GetConnection()); cmd.Parameters.Clear(); //To add parameters refer any one below methods and execute query. //Method 1: Using AddWithValue function of SqlCommand parameter property. cmd.Parameters.AddWithValue(&#34;Fname&#34;, Value1); cmd.Parameters.AddWithValue(&#34;Lname&#34;, Value2); //Method 2: Using Add function of SqlCommand parameter property. SqlParameter paramFname = new SqlParameter(); paramFname.ParameterName = &#34;@Fname&#34;; paramFname.Value = Value1; cmd.Parameters.Add(paramFname); SqlParameter paramLname = new SqlParameter(); paramLname.ParameterName = &#34;@Lname&#34;; paramLname.Value = Value2; paramLname.DbType = DbType.String; cmd.Parameters.Add(paramLname); //Method 3: Using AddRange function of SqlCommand parameter property with array. SqlParameter[] SqlParameters = new SqlParameter[] { new SqlParameter(&#34;@Fname&#34;, Value1), new SqlParameter(&#34;@Lname&#34;, Value2), }; cmd.Parameters.AddRange(SqlParameters); //Method 4: Using AddRange function of SqlCommand parameter property with list. List&lt;SqlParameter&gt; list = new List&lt;SqlParameter&gt;(); list.Add(new SqlParameter(&#34;@Fname&#34;, Value1)); list.Add(new SqlParameter(&#34;@Lname&#34;, Value2)); cmd.Parameters.AddRange(list.ToArray&lt;SqlParameter&gt;()); SqlDataReader reader = cmd.ExecuteReader(); }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/134532/Different-way-to-pass-parameter-to-command-object-in-ASPNet/https://www.aspforums.net:443/Threads/134532/Different-way-to-pass-parameter-to-command-object-in-ASPNet/Sat, 02 Jul 2016 05:58:36 GMT