Solved

dataadapter and sql procedure

Posted on 2004-09-07
12
380 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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