Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2006, 10:35 AM
Authorized User
 
Join Date: Nov 2006
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

 
Old November 14th, 2006, 02:34 PM
Authorized User
 
Join Date: Nov 2006
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
 
Old November 14th, 2006, 02:39 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old November 14th, 2006, 03:39 PM
Authorized User
 
Join Date: Nov 2006
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
 
Old November 14th, 2006, 03:45 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old November 14th, 2006, 03:48 PM
Authorized User
 
Join Date: Nov 2006
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.

 
Old November 14th, 2006, 03:51 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old November 14th, 2006, 03:58 PM
Authorized User
 
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now it produces no results. What now

 
Old November 14th, 2006, 04:03 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old November 14th, 2006, 04:07 PM
Authorized User
 
Join Date: Nov 2006
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






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





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