Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

dataadapter and sql procedure

Posted on 2004-09-07
12
382 Views
Last Modified: 2010-04-23
Hi,
I create a VB.Net program which get data from SQL server. My DataAdapter link to a SQL store procedure (I use DataAdapter Configuration Wizard), but it does not understand the table with "#" (#test). This is my store proc:
create  PROC category_get_test
AS
BEGIN
      SET NOCOUNT ON
      create table #test
      (
            id char(2),
            name char(50)
      )
      
      insert into #test
      select id, name
      from category

      select id, name from #test
      SET NOCOUNT OFF
END
How can I fix this? Please help.
Thanks.
0
Comment
Question by:khanhna
  • 4
  • 3
  • 2
12 Comments
 
LVL 8

Expert Comment

by:razo
ID: 12003884
when u run the stored procedure does it give the error or only when u run it through the adapter
0
 

Author Comment

by:khanhna
ID: 12004565
I use DataAdapter Configuration Wizard to set the sqlcommand for the adapter (at design time). At the step "Bind Command to Existing stored procedure", I select the stored then go to next step, the error msg is: Invalid object name "#test".
0
 
LVL 8

Expert Comment

by:razo
ID: 12004691
i meant wheen u run ur stored procedure from the enterprise manager does it run correctly without errors?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:khanhna
ID: 12004854
yes, it is correct.
0
 
LVL 7

Expert Comment

by:natloz
ID: 12007460
I think it is because you are using a temporary table...the # is a temporary table that is dropped at the end of the user connection...You may need to create a permenant table and then run the following stored proc...this should work.
I would use a TEMP table for holding values within the stored proc for calculation/manipulation purposes and either return an @ReturnID or a Query from a permenant table...

eg...
create table tblTest
     (
          id char(2),
          name char(50)
     )


create  PROC category_get_test
AS
BEGIN
     SET NOCOUNT ON
         
     insert into tblTest
     select id, name
     from category

     select id, name from tblTest
     SET NOCOUNT OFF
END
0
 

Author Comment

by:khanhna
ID: 12012326
Of course using a permanent table is ok but i would like a temporary table. We have a lot of users running this store, so it will create a lot of tables.
Is there other way?
0
 
LVL 7

Expert Comment

by:natloz
ID: 12017259
So you have tried my approach to make sure that you are able to successfully connect and use a stored procedure in this way? I am just making sure that it is not another problem other then the temporary table.

I think the problem is that you are using a local temporary table that gets destroyed when the user connection closes.

Why could you not just return the results

create  PROC category_get_test
AS
BEGIN
     SET NOCOUNT ON
     
     select id, name
     from category

     SET NOCOUNT OFF
END
0
 

Author Comment

by:khanhna
ID: 12024391
of course we can do like this. this is just an example. I ask for the case that we need to calculate within the stote proc so we need to user temporary table.
0
 
LVL 7

Accepted Solution

by:
natloz earned 200 total points
ID: 12027050
Well, since a temp local table is scoped to a single SQL connection, the table will be destroyed. I think you need to approach this differently to try and obtain your results. For instance, bringing back a dataset of real values and manipulating them in code from your front end, or designing queries that return result sets from your actual tables. Local temp tables can be used to do calculating within your stored proc, but can not be returned to VB.net since they are scoped to the connection and destroyed upon leaving the procedure.

Here is another person with a similar problem...

http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=251029
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need a starter for ETL protocol? 4 65
Import Data from Multiple Text Files in Excel 12 58
vb.net and creating a class 5 20
Help with preventing selection from a combobox 11 34
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question