Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ExecuteNonQuery doesn't respect local tables
Message
From
10/11/2005 12:11:08
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
10/11/2005 12:03:54
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
VB.NET 1.1
OS:
Windows XP SP1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01067192
Message ID:
01067242
Views:
17
>>To all,
>>
>>I'm running the ExecuteNonQuery method of a standard ADO.NET SQLCommand class. When I create a local table (CREATE TABLE #myTable ...) I get an error message "Invalid object name '#myTable'".
>>
>>It's not my syntax, I'm using code that's derived from code I developed to create and load a DB via Query Analyzer.
>>
>>I can create, populate and drop "regular" tables, but ADO.NET/SQL Server doesn't like the '#'.
>>
>>TIA,
>>Thom C.
>
>Thom,
>It works for me. Do you get the error when you create it? Or when you disconnect and connect again?
>Cetin
Here is a sample that worked:
using System;
using System.Data;
using System.Data.SqlClient;
class test
{
  static void Main(string[] args)
 {
       SqlConnection sConn = new SqlConnection 
      ("Data Source=(local);integrated Security=sspi;");
       string strCreate = 
@"CREATE TABLE #myTemp (myVal varchar(10))
INSERT INTO #myTemp VALUES ('hello')
INSERT INTO #myTemp VALUES ('there')
INSERT INTO #myTemp VALUES ('again')";

       string strQuery = "SELECT * FROM #myTemp where myVal like '%e%'";
       
       SqlCommand cmd = new SqlCommand(strCreate, sConn);
       sConn.Open();
       cmd.ExecuteNonQuery();

       SqlCommand cmdQ = new SqlCommand(strQuery, sConn);
       SqlDataReader rdr = cmdQ.ExecuteReader();
       while (rdr.Read())
       {
        Console.WriteLine(rdr.GetString(0));
       }
       rdr.Close();
       sConn.Close();
 }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform