C
CSINVA
I need to be able to pass a variable to a function and then have the
function return me a variable.
I need to pass GetUsrID Tom and get back the corresponding UserID
associated with tom by running a stored procedure. Then pupule a file
called lblUserID.text with the result_sUserID data.
Here is the code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
some sufff.....
subdomain = tom
Dim result_sUserID As Integer
'GetUserID
GetUserID(Subdomain, result_sUserID)
'Populate lblUserId with result_sUserID
result_sUserID = lblUserID.Text
End Sub
Public Function GetUserID(ByVal Subdomain As String, ByRef
Result_sUserID As Integer) As Integer
Dim sUserID As Integer
'Read SQL Server configuration from web.config
Dim strConnectionString As String =
System.Configuration.ConfigurationManager.ConnectionStrings("SiteSQLServer").ConnectionString
'Create new connection based on web.confg file informaiton
Dim objConnection As SqlClient.SqlConnection = New
SqlClient.SqlConnection(strConnectionString)
'Open the Connection
Try
objConnection.Open()
Catch ex As Exception
End Try
Dim myCommand As New SqlCommand("P4YS_GetUserID",
objConnection)
Try
myCommand.CommandType = Data.CommandType.StoredProcedure
'need to pass Subdomain Parameter to the system for the
Stored Procedure
myCommand.Parameters.AddWithValue("@UserWebSite",
Subdomain)
objConnection.Open()
Catch ex As Exception
End Try
Dim myReader As SqlDataReader = myCommand.ExecuteReader
'Read in the first record and grab the first column and putin
lblUserID.text label
Do While myReader.Read()
'look at column "userid" and set the value to sUserID
sUserID = myReader.Item("Userid")
Loop
myReader.Close()
myReader = Nothing
objConnection.Close()
'Return sUserID
Result_sUserID = sUserID
End Function
function return me a variable.
I need to pass GetUsrID Tom and get back the corresponding UserID
associated with tom by running a stored procedure. Then pupule a file
called lblUserID.text with the result_sUserID data.
Here is the code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
some sufff.....
subdomain = tom
Dim result_sUserID As Integer
'GetUserID
GetUserID(Subdomain, result_sUserID)
'Populate lblUserId with result_sUserID
result_sUserID = lblUserID.Text
End Sub
Public Function GetUserID(ByVal Subdomain As String, ByRef
Result_sUserID As Integer) As Integer
Dim sUserID As Integer
'Read SQL Server configuration from web.config
Dim strConnectionString As String =
System.Configuration.ConfigurationManager.ConnectionStrings("SiteSQLServer").ConnectionString
'Create new connection based on web.confg file informaiton
Dim objConnection As SqlClient.SqlConnection = New
SqlClient.SqlConnection(strConnectionString)
'Open the Connection
Try
objConnection.Open()
Catch ex As Exception
End Try
Dim myCommand As New SqlCommand("P4YS_GetUserID",
objConnection)
Try
myCommand.CommandType = Data.CommandType.StoredProcedure
'need to pass Subdomain Parameter to the system for the
Stored Procedure
myCommand.Parameters.AddWithValue("@UserWebSite",
Subdomain)
objConnection.Open()
Catch ex As Exception
End Try
Dim myReader As SqlDataReader = myCommand.ExecuteReader
'Read in the first record and grab the first column and putin
lblUserID.text label
Do While myReader.Read()
'look at column "userid" and set the value to sUserID
sUserID = myReader.Item("Userid")
Loop
myReader.Close()
myReader = Nothing
objConnection.Close()
'Return sUserID
Result_sUserID = sUserID
End Function