Visual Basic .NET Forums  

Go Back   Visual Basic .NET Forums > VB.NET > Winforms Data Access

Winforms Data Access VB.NET development for data access and back-end related areas

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-10-2008, 6:23 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: May 2008
Location: South Africa PTA
Posts: 16
Reputation: 16
wstevens is on a distinguished programming path ahead
Default QueriesTableAdapter returning 0 value

Hi All

I have researched this problem and found info but none have proper solutions. I have a stored procedure. The stored procedure returns a value of 1 if the column exists in a specific table and 0 if not.

I created a QueriesTableAdapter in a Dataset telling it to use the existing stored procedure. I select it to return Single value.

If I test the query in dataset design by preview data it returns the required value correctly, however if I call it from VB.Net it always returns 0.

Here is my code

Code:
Dim scalarQueriesTableAdapter As DSMetricsTableAdapters.QueriesTableAdapter

        scalarQueriesTableAdapter = New DSMetricsTableAdapters.QueriesTableAdapter

        Dim returnValue As Integer

        returnValue = CType(scalarQueriesTableAdapter.CheckMetrics("Department", "tbl_Metrics"), Integer)

Here is my stored procedure

Code:
@ColumnName varchar(100),
@TableName varchar(100)

AS
	
IF EXISTS(SELECT 1 FROM Syscolumns WHERE NAME= @ColumnName AND id=OBJECT_ID(@TableName))
		
RETURN 1

Last edited by JohnH; 11-19-2008 at 6:38 PM. Reason: formatted post for readability
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-11-2008, 12:49 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: May 2008
Location: South Africa PTA
Posts: 16
Reputation: 16
wstevens is on a distinguished programming path ahead
Default

Hi all "Solution"

I hope this helps everybody else having the same problem. ScalarQueriesTableAdapter returning 0 value from a stored procedure

Create your stored procedure with a RETURN value as normal. Then open dataset designer and drag a QueriesTableAdapter onto the design screen. Create a query and use existing stored procedure you created.

Then edit the Partial class for the named query and add the code below.

Code:
  Public Function GetReturnValue(ByVal commandIndex As Integer) As Object

            Return Me._commandCollection(commandIndex).Parameters(0).Value

        End Function

Your VB code will now look like this.

Code:
Dim scalarQueriesTableAdapter As DSMetricsTableAdapters.QueriesTableAdapter
        scalarQueriesTableAdapter = New DSMetricsTableAdapters.QueriesTableAdapter
        scalarQueriesTableAdapter.CheckMetrics("Department", "tbl_Metrics")
        Dim returnValue As Integer
        returnValue = scalarQueriesTableAdapter.GetReturnValue(0)

I hope this helps somebody

Last edited by JohnH; 11-19-2008 at 6:38 PM. Reason: formatted post for readability
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-11-2008, 1:21 AM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 5,308
Reputation: 415
jmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NETjmcilhinney master of VB.NET
Default

Please post in the appropriate forum for your topic. Moved from GDI+.
__________________
Essential: Multiple Forms
101 Samples: 2002 | 2003 | 2005Free Components: WFC | XPCC | ElementsEx | VBPP | ADO.NET/MySQL | VisualStyles | NPlot | SDFTutorials: Home & Learn | Start VB.NET | Learn VB.NETFavourites: MSDN | WinForms.NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On





All times are GMT -4. The time now is 11:54 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0


For advertising opportunities click here.