Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 14th, 2006, 10:35 AM
Authorized User
 
Join Date: Nov 2006
Location: Lorain, OH, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically populate a label

I have a problem with some code that I am writing. The code looks like this:

Code:
    Public Function GetLevel5Manager(ByVal strCriteria As String) As DataTable
        Try
            Dim strConn As String = HttpContext.Current.Session("ConnStr")
            Dim conn As New SqlConnection(strConn)
            Dim cmd As SqlCommand
            Dim strCrit As String = Mid(strCriteria, 9, 11)

            conn.Open()
            cmd = conn.CreateCommand()
            With cmd
                .CommandText = "sp_PopulateLevel5Manager"
                .CommandType = CommandType.StoredProcedure
                .Parameters.Add("@DisplayValue", SqlDbType.NVarChar, 50)
                .Parameters.Add("@Lvl5Mgr", SqlDbType.NVarChar, 50)
                .Parameters("@DisplayValue").Value = strCrit
                .Parameters("@DisplayValue").Direction = ParameterDirection.Input
                '.Parameters("@Lvl5Mgr").Value
                .Parameters("@Lvl5Mgr").Direction = ParameterDirection.ReturnValue
            End With
            Dim dtLvl5Mgrs As New DataTable
            Dim da As New SqlDataAdapter
            da = New SqlDataAdapter(cmd)
            da.Fill(dtLvl5Mgrs)

            conn.Close()

            'lblLevel5Manager.Text = Convert.ToString(@Lvl5Mgr)
            Return dtLvl5Mgrs




        Catch ex As Exception
            Dim sTemp As String
            sTemp = ex.Message
        End Try
    End Function
What I am trying to accomplish is to populate lblLevel5Manager with the data stored in dtLvl5Mgrs. How would I accomplish this? I am stuck

Reply With Quote
  #2 (permalink)  
Old November 14th, 2006, 02:34 PM
Authorized User
 
Join Date: Nov 2006
Location: Lorain, OH, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have got the code to work but it returns a zero not the text that I need. Does anyone have any ideas why? Here is the revised code

Code:
    Public Function GetLevel5Manager(ByVal strCriteria As String) As DataTable
        Try
            Dim strConn As String = HttpContext.Current.Session("ConnStr")
            Dim conn As New SqlConnection(strConn)
            Dim cmd As SqlCommand
            Dim strCrit As String = Mid(strCriteria, 10, 8)

            conn.Open()
            cmd = conn.CreateCommand()
            With cmd
                .CommandText = "sp_PopulateLevel5Manager"
                .CommandType = CommandType.StoredProcedure
                .Parameters.Add("@DisplayValue", SqlDbType.NVarChar, 50)
                .Parameters.Add("@Lvl5Mgr", SqlDbType.NVarChar, 50)
                .Parameters("@DisplayValue").Value = strCrit
                .Parameters("@DisplayValue").Direction = ParameterDirection.Input
                .Parameters("@Lvl5Mgr").Direction = ParameterDirection.ReturnValue
            End With
            'Dim dtLvl5Mgrs As New DataTable
            'Dim da As New SqlDataAdapter
            'da = New SqlDataAdapter(cmd)
            'da.Fill(dtLvl5Mgrs)

            nullcuteScalar()
            'lblLevel5Manager.Text = Convert.ToString(@Lvl5Mgr)
            lblLevel5Manager.Text = Convert.ToString(cmd.Parameters("@Lvl5Mgr").Value)
            'Return dtLvl5Mgrs

            conn.Close()




        Catch ex As Exception
            Dim sTemp As String
            sTemp = ex.Message
        End Try
    End Function
Reply With Quote
  #3 (permalink)  
Old November 14th, 2006, 02:39 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. a quick idea (since i don't have the SP to check out) try add
Code:
SET NOCOUNT ON
and if that's not the problem please copy the SP here.. do you receive data when you try it??

HTH

Gonzalo
Reply With Quote
  #4 (permalink)  
Old November 14th, 2006, 03:39 PM
Authorized User
 
Join Date: Nov 2006
Location: Lorain, OH, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the stored Procedure. I am still getting zero for the result set

Code:
CREATE    PROCEDURE dbo.sp_PopulateLevel5Manager @DisplayValue NVARCHAR(50)  OUTPUT
AS

SET NOCOUNT ON

DECLARE @Lvl5Mgr NVARCHAR(50)

SELECT @Lvl5Mgr=U.FullName FROM DropDownData D, Users U WHERE D.DropDownCategory = 'Level5' AND D.DisplayValue=@DisplayValue and D.Misc1 = U.Associate_ID


GO
Reply With Quote
  #5 (permalink)  
Old November 14th, 2006, 03:45 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mmm.. where are you executing the Command?? i don't see any executescalar (that's the best option even to not use an output parameter) or any other execute. Also why are you declaring @DisplayValue as OUTPUT??

HTH

Gonzalo
Reply With Quote
  #6 (permalink)  
Old November 14th, 2006, 03:48 PM
Authorized User
 
Join Date: Nov 2006
Location: Lorain, OH, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The executescalar is in the vb code for some reason it is showing up nullcuteScalar() in the second code posting that I have.

Reply With Quote
  #7 (permalink)  
Old November 14th, 2006, 03:51 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. executescalar will return the result directly...
use this
Code:
lblLevel5Manager.Text = Convert.ToString(cmd.executescalar)
HTH

Gonzalo
Reply With Quote
  #8 (permalink)  
Old November 14th, 2006, 03:58 PM
Authorized User
 
Join Date: Nov 2006
Location: Lorain, OH, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now it produces no results. What now

Reply With Quote
  #9 (permalink)  
Old November 14th, 2006, 04:03 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

can you confirm that the SP drops result if you try it alone?? (outside of the code, just try the SP and see what's returning)... maybe the parameters you are passing are wrong.


HTH

Gonzalo
Reply With Quote
  #10 (permalink)  
Old November 14th, 2006, 04:07 PM
Authorized User
 
Join Date: Nov 2006
Location: Lorain, OH, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can confirm that the parameters are passing correctly. That is what I thought about this too. Is that the parameters were wrong but they produce the desired results when I run it in query analyzer.

This is really confusing me

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to see a label hombre Java Basics 3 March 4th, 2008 06:15 AM
Can I call a method that populate a Label??? cp75 ASP.NET 1.0 and 1.1 Basics 2 January 12th, 2007 05:39 AM
Dynamically displaying textboxes and label lily611 General .NET 1 December 15th, 2004 06:59 PM
Dynamically populate crystal report from .NET DTCT Crystal Reports 0 November 12th, 2004 11:46 AM



All times are GMT -4. The time now is 02:41 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.