 |
| 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
|
|
|
|

November 14th, 2006, 10:35 AM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 14th, 2006, 02:34 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 14th, 2006, 02:39 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
hi there.. a quick idea (since i don't have the SP to check out) try add
and if that's not the problem please copy the SP here.. do you receive data when you try it??
HTH
Gonzalo
|
|

November 14th, 2006, 03:39 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 14th, 2006, 03:45 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
|
|

November 14th, 2006, 03:48 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The executescalar is in the vb code for some reason it is showing up nullcuteScalar() in the second code posting that I have.
|
|

November 14th, 2006, 03:51 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
well.. executescalar will return the result directly...
use this
Code:
lblLevel5Manager.Text = Convert.ToString(cmd.executescalar)
HTH
Gonzalo
|
|

November 14th, 2006, 03:58 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Now it produces no results. What now
|
|

November 14th, 2006, 04:03 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
|
|

November 14th, 2006, 04:07 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |