PC Review


Reply
Thread Tools Rate Thread

Creating a temporary table in a SqlCommand with Parameters fails

 
 
Mark Rendle
Guest
Posts: n/a
 
      5th Jul 2005
For some reason, if I create a temporary table in a SqlCommand which has
parameters, it doesn't get created properly, although no exception is
thrown and ExecuteNonQuery returns the correct number of rows.

So

cmd.CommandText = "create table #temp (col int); insert into #temp values
(1)";
cmd.Connection.Open();
cmd.ExecuteNonQuery(); // returns 1, temp table has been created in tempdb

works fine, but

cmd.CommandText = "create table #temp (col int); insert into #temp values
(@param)";
cmd.Parameters.Add("@param", 1);
cmd.Connection.Open();
cmd.ExecuteNonQuery(); // returns 1, temp table has not been created.

fails utterly.

Is there a proper reason for this or is it just another one of those things?


 
Reply With Quote
 
 
 
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      5th Jul 2005
Intriguing question. I can't get it to work either. I'm posting a bug
against Whidbey and I'll mention that it fails in Everett too.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Mark Rendle" <markdotrendleatcomputersoftwaredotcom> wrote in message
news:(E-Mail Removed)...
> For some reason, if I create a temporary table in a SqlCommand which has
> parameters, it doesn't get created properly, although no exception is
> thrown and ExecuteNonQuery returns the correct number of rows.
>
> So
>
> cmd.CommandText = "create table #temp (col int); insert into #temp values
> (1)";
> cmd.Connection.Open();
> cmd.ExecuteNonQuery(); // returns 1, temp table has been created in tempdb
>
> works fine, but
>
> cmd.CommandText = "create table #temp (col int); insert into #temp values
> (@param)";
> cmd.Parameters.Add("@param", 1);
> cmd.Connection.Open();
> cmd.ExecuteNonQuery(); // returns 1, temp table has not been created.
>
> fails utterly.
>
> Is there a proper reason for this or is it just another one of those
> things?
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
#temp table not recognized when sqlcommand has parameters =?Utf-8?B?UmljaA==?= Microsoft ADO .NET 1 3rd Nov 2006 10:37 PM
Creating a temporary table/query for subform LeMay Microsoft Access Queries 9 18th Feb 2006 03:31 AM
Need help creating temporary table from filter Darhl Thomason Microsoft Access Form Coding 11 14th Feb 2006 12:37 AM
Passing output parameters to SQL Server stored procedures through an SqlCommand object's Parameters collection Mark Rae Microsoft ADO .NET 8 26th Sep 2005 03:28 PM
Why is 2098 the maximum number of parameters in SqlCommand.Parameters Paul Clark Microsoft ADO .NET 3 24th Aug 2003 06:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:45 PM.