Passing parameters to stored procedureshttp://forums.asp.net/t/958789.aspx/1?Passing+parameters+to+stored+proceduresSat, 20 May 2006 00:36:00 -04009587891185245http://forums.asp.net/p/958789/1185245.aspx/1?Passing+parameters+to+stored+proceduresPassing parameters to stored procedures <p>Hi,</p> <p>If the existing ado code is using a stored procedure<br> &nbsp;and passing parameters, in ado.net is creating<br> parameters and adding to the parameter collection<br> the only way ??<br> &nbsp;Can I do the following in ado.net ?<br> <br> strSQL = &quot;sp_xxx&quot; &amp; dr(&quot;loc_cd&quot;) &amp; &quot;,&quot; &amp; q(as_of_date)&nbsp;&amp; &quot;<br> sc.CommandType = CommandType.StoredProcedure</p> <p>sc.CommandText = strSQL<br> </p> <p>Thanks in advance,</p> 2006-02-01T02:37:04-05:001202713http://forums.asp.net/p/958789/1202713.aspx/1?Re+Passing+parameters+to+stored+proceduresRe: Passing parameters to stored procedures No. You cannot.<br> You have to instaniate each parameter first, give the value and then add into the instance.<br> <br> 2006-02-19T01:52:37-05:001225506http://forums.asp.net/p/958789/1225506.aspx/1?Re+Passing+parameters+to+stored+proceduresRe: Passing parameters to stored procedures <p>An example is approriate here:</p> <p>string cSelect = &quot;dbo.Test&quot;;</p> <font size="3"> <p></font><font color="#008080" size="3">SqlDataAdapter</font><font size="3"> DataAdapter = </font><font color="#0000ff" size="3">new</font><font size="3"> </font><font color="#008080" size="3">SqlDataAdapter</font><font size="3">( cSelect, conConstant );</p> <p>DataAdapter.SelectCommand.CommandType = </font><font color="#008080" size="3">CommandType</font><font size="3">.StoredProcedure;</p> <p>DataAdapter.SelectCommand.Parameters.AddWithValue( </font><font color="#800000" size="3">&quot;@iClientID&quot;</font><font size="3">, (</font><font color="#008080" size="3">Guid</font><font size="3">)Session[ </font><font color="#800000" size="3">&quot;gClientID&quot;</font><font size="3"> ] );</font></p> <p><font size="3">Hope this helps,</font></p> <p><font size="3">Nick H</p> </font> 2006-03-14T04:40:28-05:001226591http://forums.asp.net/p/958789/1226591.aspx/1?Re+Passing+parameters+to+stored+proceduresRe: Passing parameters to stored procedures <p>kmr,</p> <p>Adding Parameters to the parameters collection is more secure and automatically figures out the type of the parameter (Varchar, Int, etc).</p> <p>Thanks,</p> 2006-03-15T02:57:10-05:001291312http://forums.asp.net/p/958789/1291312.aspx/1?Re+Passing+parameters+to+stored+proceduresRe: Passing parameters to stored procedures <p>I created a simple stored procedure to add a record to my [movies] table:</p> <p>CREATE PROCEDURE dbo.AddMovie<br> (@isdn nvarchar(10), @title varchar(80), @rating varchar(50),<br> @widescreen&nbsp; varchar(1), @genre&nbsp; varchar(80), @plot&nbsp; varchar(250),<br> @director&nbsp; varchar(50), @producer&nbsp; varchar(50))<br> AS<br> INSERT INTO dbo.movies</p> <p>VALUES<br> &nbsp;(@isdn,&nbsp;&nbsp;@title,&nbsp;&nbsp;@rating,&nbsp;&nbsp;@widescreen,&nbsp;&nbsp;@genre,<br> &nbsp;@plot,&nbsp;&nbsp;@director,&nbsp;&nbsp;@producer)</p> <p>My question is: &quot;How do I pass the parematers to the stored procedure when my ASP page says:</p> <font color="#0000ff" size="2"> <p>&lt;</font><font color="#800000" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#800000" size="2">SqlDataSource</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;SqlDataSource1&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;<br> </font><font color="#ff0000" size="2">ConnectionString</font><font color="#0000ff" size="2">=&quot;</font><font size="2">&lt;%&#36; ConnectionStrings:chucksaConnectionString %&gt;</font><font color="#0000ff" size="2">&quot;<br> </font><font color="#ff0000" size="2">SelectCommand</font><font color="#0000ff" size="2">=&quot;SELECT * FROM [movies]&quot;</font><font size="2"> </font><font color="#ff0000" size="2">ProviderName</font><font color="#0000ff" size="2">=&quot;</font><font size="2">&lt;%&#36; ConnectionStrings:chucksaConnectionString.ProviderName %&gt;</font><font color="#0000ff" size="2">&quot;</font><font size="2"> <br> </font><font color="#ff0000" size="2">DeleteCommand</font><font color="#0000ff" size="2">=&quot;DELETE FROM movies&quot;<br> </font><font color="#ff0000" size="2">InsertCommand</font><font color="#0000ff" size="2">=&quot;addMovie&quot;</font><font size="2"> </font><font color="#ff0000" size="2">InsertCommandType</font><font color="#0000ff" size="2">=&quot;StoredProcedure&quot;<br> </font><font color="#ff0000" size="2">UpdateCommand</font><font color="#0000ff" size="2">=&quot;UPDATE movies SET&quot;&gt;<br> </font><font color="#0000ff" size="2">&lt;/</font><font color="#800000" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#800000" size="2">SqlDataSource</font><font color="#0000ff" size="2">&gt;</font></p> <p><font size="2"><font color="#000000">I am using a DetailsView control - Is this an issue of data binding?</font></p> </font> <p><font color="#000000">Regards,<br> </font>Chuck</p> 2006-05-20T00:36:00-04:00