<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: ASP .NET SQL Statement</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/asp-net-sql-statement/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/asp-net-sql-statement/</link>
	<description></description>
	<lastBuildDate>Wed, 19 Jun 2013 01:14:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: charlesjc</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/asp-net-sql-statement/#comment-36067</link>
		<dc:creator>charlesjc</dc:creator>
		<pubDate>Mon, 05 Mar 2007 08:47:25 +0000</pubDate>
		<guid isPermaLink="false">#comment-36067</guid>
		<description><![CDATA[Wolfman24,

  The ExecuteScalar function should return a null reference if the resultset is empty.  Since that is not working for some reason, try putting a breakpoint on the start of the If block and check the return value of the ExecuteScalar call, when the record does not exist.  Whatever that value is, use that as your condition for inserting.

Charles]]></description>
		<content:encoded><![CDATA[<p>Wolfman24,</p>
<p>  The ExecuteScalar function should return a null reference if the resultset is empty.  Since that is not working for some reason, try putting a breakpoint on the start of the If block and check the return value of the ExecuteScalar call, when the record does not exist.  Whatever that value is, use that as your condition for inserting.</p>
<p>Charles</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wolfman24</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/asp-net-sql-statement/#comment-36068</link>
		<dc:creator>wolfman24</dc:creator>
		<pubDate>Fri, 02 Mar 2007 16:05:45 +0000</pubDate>
		<guid isPermaLink="false">#comment-36068</guid>
		<description><![CDATA[Thanks, CharlesJC. Your suggestions along with a few other tweaks have gotten the form up and running. Except for 1 issue. The UPDATE works like it should. The INSERT however does not work. If I submit a new entry it looks like everything completed properly but the data isn&#039;t showing in the SQL table. It&#039;s almost like it tries to update but there&#039;s nothing to update.

Could the problem be with &#039;1Command IS NOTHING&#039;? It seems like it never finds this to be true and always goes to ELSE. Is there another way to check this?

Again, thanks for all your help!]]></description>
		<content:encoded><![CDATA[<p>Thanks, CharlesJC. Your suggestions along with a few other tweaks have gotten the form up and running. Except for 1 issue. The UPDATE works like it should. The INSERT however does not work. If I submit a new entry it looks like everything completed properly but the data isn&#8217;t showing in the SQL table. It&#8217;s almost like it tries to update but there&#8217;s nothing to update.</p>
<p>Could the problem be with &#8217;1Command IS NOTHING&#8217;? It seems like it never finds this to be true and always goes to ELSE. Is there another way to check this?</p>
<p>Again, thanks for all your help!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sheldonlinker</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/asp-net-sql-statement/#comment-36069</link>
		<dc:creator>sheldonlinker</dc:creator>
		<pubDate>Fri, 02 Mar 2007 14:29:08 +0000</pubDate>
		<guid isPermaLink="false">#comment-36069</guid>
		<description><![CDATA[Regarding:

If (&quot;SELECT DataID FROM table1&quot;) = UserID
Then Update
Else Insert
End If

That&#039;s 2 queries every time.  Do the update (1 query) and see if any rows were affected.  If not, do the insert (possible second query).

If you really really want to use an IF, the IF should be:

IF EXISTS(SELECT 1 FROM table1 WHERE dataId=userId) THEN
UPDATE...;
ELSE
INSERT...;
END IF;]]></description>
		<content:encoded><![CDATA[<p>Regarding:</p>
<p>If (&#8220;SELECT DataID FROM table1&#8243;) = UserID<br />
Then Update<br />
Else Insert<br />
End If</p>
<p>That&#8217;s 2 queries every time.  Do the update (1 query) and see if any rows were affected.  If not, do the insert (possible second query).</p>
<p>If you really really want to use an IF, the IF should be:</p>
<p>IF EXISTS(SELECT 1 FROM table1 WHERE dataId=userId) THEN<br />
UPDATE&#8230;;<br />
ELSE<br />
INSERT&#8230;;<br />
END IF;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: charlesjc</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/asp-net-sql-statement/#comment-36070</link>
		<dc:creator>charlesjc</dc:creator>
		<pubDate>Fri, 02 Mar 2007 13:48:32 +0000</pubDate>
		<guid isPermaLink="false">#comment-36070</guid>
		<description><![CDATA[Wolfman24,

  Here is your code rearranged a bit:

Try
&#039;Create the connection first
conNCIGFDN = New SqlConnection(&quot;Server=server;UID=uid;PWD=pass;database=DB&quot;)

&#039;Opening the coneection is optional.
conNCIGFDN.Open()

&#039;Create the SQLCommand using the connection you just created.  The other SQLCommand objects will use the same SQLConnection object.
lCommand = New SqlCommand(&quot;SELECT UserID FROM dnn_KB_XMod_Index_VC500 WHERE UserID = &quot;&quot;&quot; &amp; UserID &amp; &quot;&quot;&quot;&quot;, conNCIGFDN)
If lCommand.ExecuteScalar Is Nothing Then
strInsert = &quot;INSERT...
cmdInsert = New SqlCommand(strInsert, conNCIGFDN)
cmdInsert.ExecuteNonQuery()
Else
strUpdate = &quot;UPDATE....
cmdUpdate = New SqlCommand(strUpdate, conNCIGFDN)
cmdUpdate.ExecuteNonQuery()
End If
&#039;if you explicitly open the connection, you should close it.
conNCIGFDN.Close()


What happens now?]]></description>
		<content:encoded><![CDATA[<p>Wolfman24,</p>
<p>  Here is your code rearranged a bit:</p>
<p>Try<br />
&#8216;Create the connection first<br />
conNCIGFDN = New SqlConnection(&#8220;Server=server;UID=uid;PWD=pass;database=DB&#8221;)</p>
<p>&#8216;Opening the coneection is optional.<br />
conNCIGFDN.Open()</p>
<p>&#8216;Create the SQLCommand using the connection you just created.  The other SQLCommand objects will use the same SQLConnection object.<br />
lCommand = New SqlCommand(&#8220;SELECT UserID FROM dnn_KB_XMod_Index_VC500 WHERE UserID = &#8220;&#8221;" &amp; UserID &amp; &#8220;&#8221;"&#8221;, conNCIGFDN)<br />
If lCommand.ExecuteScalar Is Nothing Then<br />
strInsert = &#8220;INSERT&#8230;<br />
cmdInsert = New SqlCommand(strInsert, conNCIGFDN)<br />
cmdInsert.ExecuteNonQuery()<br />
Else<br />
strUpdate = &#8220;UPDATE&#8230;.<br />
cmdUpdate = New SqlCommand(strUpdate, conNCIGFDN)<br />
cmdUpdate.ExecuteNonQuery()<br />
End If<br />
&#8216;if you explicitly open the connection, you should close it.<br />
conNCIGFDN.Close()</p>
<p>What happens now?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wolfman24</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/asp-net-sql-statement/#comment-36071</link>
		<dc:creator>wolfman24</dc:creator>
		<pubDate>Fri, 02 Mar 2007 13:01:17 +0000</pubDate>
		<guid isPermaLink="false">#comment-36071</guid>
		<description><![CDATA[Thank you for your help CharlesJC. Again, I&#039;m a newbie so I&#039;m sure my inexperience is showing. I can&#039;t get it to work properly and I think it&#039;s b/c off wrong syntax.

Try
lCommand = New SqlCommand(&quot;SELECT UserID FROM dnn_KB_XMod_Index_VC500 WHERE UserID = &quot;&quot;&quot; &amp; UserID &amp; &quot;&quot;&quot;&quot;, conNCIGFDN)
	If lCommand.ExecuteScalar Is Nothing Then
		conNCIGFDN = New SqlConnection(&quot;Server=server;UID=uid;PWD=pass;database=DB&quot;)
		strInsert = &quot;INSERT...
		conNCIGFDN.Open()
		cmdInsert = New SqlCommand(strInsert, conNCIGFDN)
		cmdInsert.ExecuteNonQuery()
	Else
		strUpdate = &quot;UPDATE....
		cmdUpdate = New SqlCommand(strUpdate, conNCIGFDN)
		cmdUpdate.ExecuteNonQuery()
		conNCIGFDN.Close()
	End If
....

Any suggestions on how to get this working correctly? I&#039;m very close, thanks to this forum, to getting this to work.]]></description>
		<content:encoded><![CDATA[<p>Thank you for your help CharlesJC. Again, I&#8217;m a newbie so I&#8217;m sure my inexperience is showing. I can&#8217;t get it to work properly and I think it&#8217;s b/c off wrong syntax.</p>
<p>Try<br />
lCommand = New SqlCommand(&#8220;SELECT UserID FROM dnn_KB_XMod_Index_VC500 WHERE UserID = &#8220;&#8221;" &amp; UserID &amp; &#8220;&#8221;"&#8221;, conNCIGFDN)<br />
	If lCommand.ExecuteScalar Is Nothing Then<br />
		conNCIGFDN = New SqlConnection(&#8220;Server=server;UID=uid;PWD=pass;database=DB&#8221;)<br />
		strInsert = &#8220;INSERT&#8230;<br />
		conNCIGFDN.Open()<br />
		cmdInsert = New SqlCommand(strInsert, conNCIGFDN)<br />
		cmdInsert.ExecuteNonQuery()<br />
	Else<br />
		strUpdate = &#8220;UPDATE&#8230;.<br />
		cmdUpdate = New SqlCommand(strUpdate, conNCIGFDN)<br />
		cmdUpdate.ExecuteNonQuery()<br />
		conNCIGFDN.Close()<br />
	End If<br />
&#8230;.</p>
<p>Any suggestions on how to get this working correctly? I&#8217;m very close, thanks to this forum, to getting this to work.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.037 seconds using memcached
Object Caching 323/329 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-19 03:05:58 -->