<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Data Access and ObjectDataSource Control</title><link>http://forums.asp.net/23.aspx</link><description>Questions and discussions related to using ADO.NET for data access, and the ObjectDataSource control. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=9&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3280000.aspx</link><pubDate>Tue, 07 Jul 2009 22:07:17 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3280000</guid><dc:creator>Mikesdotnetting</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3280000.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3280000</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;Ez416:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;The problem is, the parameter in the stored procedure should be the same with the parameter declared in .net&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;&lt;p&gt;I don&amp;#39;t follow what you are saying....&lt;/p&gt;&lt;p&gt;You are passing in 2 arrays - one with the parameter names and one with the matching values.&amp;nbsp; Yes, the parameter names that you pass in to the array should match the ones in the stored procedure that you are passing in too.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3279998.aspx</link><pubDate>Tue, 07 Jul 2009 22:04:26 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3279998</guid><dc:creator>Mikesdotnetting</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3279998.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3279998</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;Ez416:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;I&amp;#39;ve tried converting it to VB&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;&lt;p&gt;Good.&amp;nbsp; You have discovered codechanger.com. I normally just change:&lt;/p&gt;&lt;pre&gt;&lt;span&gt;System.Math.Max(System.Threading.Interlocked.Increment(i),i&amp;nbsp;-&amp;nbsp;1)&amp;nbsp; &lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;span&gt;to:&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span&gt;i = i + 1&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;span&gt;Run the code to see if it works.&amp;nbsp; That way you will find out if it is correct, but at first glance, I suspect it is.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3278586.aspx</link><pubDate>Tue, 07 Jul 2009 09:29:54 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3278586</guid><dc:creator>Ez416</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3278586.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3278586</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;The problem is, the parameter in the stored procedure should be the same with the parameter declared in .net&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3278400.aspx</link><pubDate>Tue, 07 Jul 2009 08:10:19 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3278400</guid><dc:creator>Ez416</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3278400.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3278400</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;I&amp;#39;ve tried converting it to VB&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;from&lt;/strong&gt;&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;{
    using (SqlConnection conn = new SqlConnection(connstring))
    {
        SqlCommand cmd = new SqlCommand(proc, conn);
        cmd.CommandType = CommandType.StoredProcedure;
        for (int i = 0; i &amp;lt; Params.Length; i++)
        {
            cmd.Parameters.AddWithValue(Params[i], Values[i]);
        }
        conn.Open();
        cmd.ExecuteNonQuery();
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;To&lt;/strong&gt;&lt;/p&gt;&lt;pre class="vb.net" name="code"&gt;Public Shared Sub ExecNonQuery(proc As String, Params As String(), Values As [Object]())
	Using conn As New SqlConnection(connstring)
		Dim cmd As New SqlCommand(proc, conn)
		cmd.CommandType = CommandType.StoredProcedure
		Dim i As Integer = 0
		While i &amp;lt; Params.Length
			cmd.Parameters.AddWithValue(Params(i), Values(i))
			System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
		End While
		conn.Open()
		cmd.ExecuteNonQuery()
	End Using
End Sub&lt;/pre&gt;
&lt;p&gt;-------------------------------------&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;From&lt;/strong&gt;&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;string sql = DeleteAllExpired; // name of procedure
string[] p = new string{&amp;quot;id&amp;quot;};
object[] o = new object{TextBox1.Text};
ExecNonQuery(sql, p, o);&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;To&lt;/strong&gt;&lt;/p&gt;&lt;pre class="vb.net" name="code"&gt;Dim sql As String = DeleteAllExpired
&amp;#39; name of procedure
Dim p As String() = New String()
Dim o As Object() = New Object()
ExecNonQuery(sql, p, o)
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Are these correct?&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3276718.aspx</link><pubDate>Mon, 06 Jul 2009 12:16:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3276718</guid><dc:creator>Mikesdotnetting</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3276718.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3276718</wfw:commentRss><description>&lt;p&gt;Here&amp;#39;s an example:&lt;/p&gt;&lt;p&gt;public static void ExecNonQuery(string proc, string[] Params, Object[] 
Values)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (SqlConnection conn = new 
SqlConnection(connstring))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SqlCommand cmd = new 
SqlCommand(proc, conn);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd.CommandType = 
CommandType.StoredProcedure;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; Params.Length; 
i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd.Parameters.AddWithValue(Params[i], 
Values[i]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.Open();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
cmd.ExecuteNonQuery();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;This one causes an ExecuteNonQuery() command to be executed.&amp;nbsp; You just feed it a procedure name, an array of strings for the parameter names and an array of objects that provide the values to the parameters.&amp;nbsp; &lt;/p&gt;&lt;p&gt;Eg: &lt;/p&gt;&lt;p&gt;string sql = DeleteAllExpired; // name of procedure&lt;br /&gt;string[] p = new string{&amp;quot;id&amp;quot;};&lt;br /&gt;object[] o = new object{TextBox1.Text};&lt;br /&gt;ExecNonQuery(sql, p, o);&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3276154.aspx</link><pubDate>Mon, 06 Jul 2009 07:00:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3276154</guid><dc:creator>Ez416</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3276154.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3276154</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;but i wonder if how can I make my parameters flexible.&amp;nbsp; in a way for example the stored proc that will be use has 4 parameters, since my code(class) has only designed for 3 parameters only.&amp;nbsp; how can I accomplished this?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3276143.aspx</link><pubDate>Mon, 06 Jul 2009 06:53:51 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3276143</guid><dc:creator>Ez416</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3276143.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3276143</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;ok got it &lt;/p&gt;
&lt;p&gt;if modified my class &lt;/p&gt;&lt;pre class="vb.net" name="code"&gt;.CommandType = CommandType.StoredProcedure
.CommandTimeout = 4000
.Parameters.AddWithValue(&amp;quot;QType&amp;quot;, P1)
.Parameters.AddWithValue(&amp;quot;Desc1&amp;quot;, P2)
.Parameters.AddWithValue(&amp;quot;Desc2&amp;quot;, P3)&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3273814.aspx</link><pubDate>Fri, 03 Jul 2009 16:11:11 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273814</guid><dc:creator>RichardD</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273814.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3273814</wfw:commentRss><description>&lt;p&gt;The problem is that you are creating a &amp;#39;Text&amp;#39; command rather than a &amp;#39;StoredProcedure&amp;#39; command. If you set cu.CommandType to CommandType.StoredProcedure and change the query to &amp;quot;spt_PhysiciansModule&amp;quot;, the query will work.&lt;/p&gt;
&lt;p&gt;Alternatively, if you can&amp;#39;t change the command type, you need to specify the parameters in the query:&lt;/p&gt;
&lt;pre name="code" class="sql"&gt;EXEC spt_PhysiciansModule @QType = @QType, @Desc1 = @Desc1, @Desc2 = @Desc2&lt;/pre&gt;
&lt;p&gt;The names need to be specified twice so that SQL matches the parameters by name; if you just specified &amp;quot;EXEC spt_PhysicialsModule @QType, @Desc1, @Desc2&amp;quot;, the parameters would be matched by position, which may not be correct.&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3273788.aspx</link><pubDate>Fri, 03 Jul 2009 15:51:26 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273788</guid><dc:creator>hans_v</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273788.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3273788</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;cshark:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;Command parameters in .net are case sensitive&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think it is .NET that is case sensitive. I think the sensitive Collation setting&amp;nbsp;of the SQL Server requires the parameters to be case sensitive....&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3273059.aspx</link><pubDate>Fri, 03 Jul 2009 08:30:34 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273059</guid><dc:creator>cshark</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273059.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3273059</wfw:commentRss><description>&lt;p&gt;Command parameters in .net are case sensitive.&amp;nbsp;@QType is different from&amp;nbsp;@Qtype&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3273050.aspx</link><pubDate>Fri, 03 Jul 2009 08:27:12 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273050</guid><dc:creator>Ez416</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273050.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3273050</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;whats the difference?&lt;/p&gt;
&lt;p&gt;mine is &lt;/p&gt;
&lt;p&gt;cu.Parameters.AddWithValue(&amp;quot;@QType&amp;quot;, &amp;quot;A&amp;quot;)&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3273030.aspx</link><pubDate>Fri, 03 Jul 2009 08:16:27 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273030</guid><dc:creator>cshark</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273030.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3273030</wfw:commentRss><description>&lt;p&gt;You are adding the parameter as @QType in .net where as the parameter in sql is @Qtype. &lt;img src="http://forums.asp.net/tiny_mce/jscripts/tiny_mce/plugins/emotions/img/smiley-smile.gif" alt="Smile" title="Smile" border="0" /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;try the below line.&lt;/p&gt;&lt;p&gt;cu.Parameters.AddWithValue(&amp;quot;@Qtype&amp;quot;, &amp;quot;A&amp;quot;)&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3273004.aspx</link><pubDate>Fri, 03 Jul 2009 08:03:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273004</guid><dc:creator>Ez416</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273004.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3273004</wfw:commentRss><description>&lt;p&gt;Dim sQuery1 As String = &amp;quot;spt_PhysiciansModule&amp;quot;&lt;/p&gt;
&lt;p&gt;Dim cu As New SqlCommand(sQuery1, LibConn)&lt;/p&gt;
&lt;p&gt;Dim cr As System.Data.SqlClient.SqlDataReader = cu.ExecuteReader()&lt;/p&gt;
&lt;p&gt;cu.CommandType = CommandType.StoredProcedure&lt;/p&gt;
&lt;p&gt;cu.Parameters.AddWithValue(&amp;quot;@QType&amp;quot;, &amp;quot;A&amp;quot;)&lt;/p&gt;
&lt;p&gt;cu.Parameters.AddWithValue(&amp;quot;@Desc1&amp;quot;, &amp;quot;&amp;quot;)&lt;/p&gt;
&lt;p&gt;cu.Parameters.AddWithValue(&amp;quot;@Desc2&amp;quot;, &amp;quot;&amp;quot;)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Error Msg: Procedure or Function &amp;#39;spt_PhysiciansModule&amp;#39; expects parameter &lt;a href="mailto:&amp;#39;@Qtype&amp;#39;"&gt;&amp;#39;@Qtype&amp;#39;&lt;/a&gt;, which was not supplied.&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3272964.aspx</link><pubDate>Fri, 03 Jul 2009 07:41:35 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3272964</guid><dc:creator>Ez416</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3272964.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3272964</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;It doesnt work with the code above.&lt;/p&gt;</description></item><item><title>Re: how to apply paramatized queeries with this code</title><link>http://forums.asp.net/thread/3272902.aspx</link><pubDate>Fri, 03 Jul 2009 07:13:57 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3272902</guid><dc:creator>mudassarkhan</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3272902.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=3272902</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;You can read here for parameterized queries&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.aspsnippets.com/post/2009/02/09/Parameterized-Queries-ADONet.aspx"&gt;http://www.aspsnippets.com/post/2009/02/09/Parameterized-Queries-ADONet.aspx&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>