Solved

dataadapter and sql procedure

Posted on 2004-09-07
12
377 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
 

Author Comment

by:khanhna
ID: 12004854
yes, it is correct.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now