473,511 Members | 16,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return Value?

A class file named "Users.vb" has the following code:

Namespace Users
Public Class UserDetails
Public FirstName As String
Public LastName As String
Public UserName As String
Public Password As String
Public UserID As String
End Class

Public Class User
Public Function Login(ByVal UserName As String, ByVal Password
As String) As Integer
Dim iID As Integer
Dim sqlCmd As SqlCommand
Dim sqlConn As SqlConnection
Dim sqlReader As SqlDataReader

sqlConn = New SqlConnection("......")
sqlCmd = New SqlCommand("SELECT ID FROM tblUsers WHERE
UserName='" & UserName & "' AND Password='" & Password & "'", sqlConn)

sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader()

Do While (sqlReader.Read)
iID = sqlReader.GetInt32(0)
Loop
sqlConn.Close()

Return iID
End Function

Public Function GetDetails(ByVal UserID As Integer) As
UserDetails
Dim sqlCmd As SqlCommand
Dim uDetails As UserDetails
Dim sqlConn As SqlConnection
Dim sqlReader As SqlDataReader

sqlConn = New SqlConnection("........")
sqlCmd = New SqlCommand("SELECT
FirstName,LastName,UserName,Password FROM tblUsers WHERE ID=" & UserID,
sqlConn)

sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader

uDetails = New UserDetails
While (sqlReader.Read)
uDetails.FirstName = sqlReader.GetString(0)
uDetails.LastName = sqlReader.GetString(1)
uDetails.UserName = sqlReader.GetString(2)
uDetails.Password = sqlReader.GetString(3)
uDetails.UserID = UserID
End While

sqlReader.Close()
sqlConn.Close()

Return uDetails
End Function
End Class
End Namespace

I successfully compiled the above class into "Users.dll" & this is how
I am using the DLL in an ASPX page:

<%@ Import Namespace="Users" %>
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
Dim boUser As User
Dim boUserDetails As UserDetails

pnlLogin.Visible = True
pnlShowMsg.Visible = False

boUser = New User
boUserDetails = New UserDetails

boUserDetails = boUser.GetDetails(????)
lblMessage.Text = "Hello " & boUserDetails.FirstName
Else
pnlLogin.Visible = False
pnlShowMsg.Visible = True
End If
End Sub

Sub Login(ByVal obj As Object, ByVal ea As EventArgs)
Dim boUser As User
Dim iUID As Integer

boUser = New User
iUID = boUser.Login(txtUserName.Text, txtPassword.Text)
End Sub
</script>

<form runat="server">
<asp:Panel ID="pnlLogin" runat="server">
UserName: <asp:TextBox ID="txtUserName" runat="server"/><br>
Password: <asp:TextBox ID="txtPassword" TextMode="password"
runat="server"/><br>
<asp:Button ID="btnLogin" OnClick="Login" Text="LOGIN" runat="server"/>
</asp:Panel>

<asp:Panel ID="pnlShowMsg" runat="server">
<asp:Label ID="lblMessage" runat="server"/>
</asp:Panel>
</form>

When the ASPX page loads for the first time, users see the 2 TextBoxes.
When a user enters his UserName & Password, assuming that the UserName
& Password exists in the database table, after executing the following
code line in the Page_Load sub

boUserDetails = boUser.GetDetails(????)

the Label "lblMessage" should display a message but I can't figure out
how to pass the ID (corresponding to the UserName & Password entered by
the user) to the "GetDetails" function which expects an integer ID
parameter under the class named "User". For e.g. if the ID
corresponding to the UserName & Password entered by the user is, say, 5
then the GetDetails line in the Page_Load sub should evaluate to

boUserDetails = boUser.GetDetails(5)

Can someone please tell me how do I pass the ID value to the
"GetDetails" function after the user enters a UserName & Password in
the 2 TextBoxes?

Thanks,

Arpan

Sep 3 '06 #1
1 1224
you have to select details based on something user provides.

Modify select statement to use login info.
"Arpan" <ar******@hotmail.comwrote in message news:11**********************@74g2000cwt.googlegro ups.com...
>A class file named "Users.vb" has the following code:

Namespace Users
Public Class UserDetails
Public FirstName As String
Public LastName As String
Public UserName As String
Public Password As String
Public UserID As String
End Class

Public Class User
Public Function Login(ByVal UserName As String, ByVal Password
As String) As Integer
Dim iID As Integer
Dim sqlCmd As SqlCommand
Dim sqlConn As SqlConnection
Dim sqlReader As SqlDataReader

sqlConn = New SqlConnection("......")
sqlCmd = New SqlCommand("SELECT ID FROM tblUsers WHERE
UserName='" & UserName & "' AND Password='" & Password & "'", sqlConn)

sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader()

Do While (sqlReader.Read)
iID = sqlReader.GetInt32(0)
Loop
sqlConn.Close()

Return iID
End Function

Public Function GetDetails(ByVal UserID As Integer) As
UserDetails
Dim sqlCmd As SqlCommand
Dim uDetails As UserDetails
Dim sqlConn As SqlConnection
Dim sqlReader As SqlDataReader

sqlConn = New SqlConnection("........")
sqlCmd = New SqlCommand("SELECT
FirstName,LastName,UserName,Password FROM tblUsers WHERE ID=" & UserID,
sqlConn)

sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader

uDetails = New UserDetails
While (sqlReader.Read)
uDetails.FirstName = sqlReader.GetString(0)
uDetails.LastName = sqlReader.GetString(1)
uDetails.UserName = sqlReader.GetString(2)
uDetails.Password = sqlReader.GetString(3)
uDetails.UserID = UserID
End While

sqlReader.Close()
sqlConn.Close()

Return uDetails
End Function
End Class
End Namespace

I successfully compiled the above class into "Users.dll" & this is how
I am using the DLL in an ASPX page:

<%@ Import Namespace="Users" %>
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
Dim boUser As User
Dim boUserDetails As UserDetails

pnlLogin.Visible = True
pnlShowMsg.Visible = False

boUser = New User
boUserDetails = New UserDetails

boUserDetails = boUser.GetDetails(????)
lblMessage.Text = "Hello " & boUserDetails.FirstName
Else
pnlLogin.Visible = False
pnlShowMsg.Visible = True
End If
End Sub

Sub Login(ByVal obj As Object, ByVal ea As EventArgs)
Dim boUser As User
Dim iUID As Integer

boUser = New User
iUID = boUser.Login(txtUserName.Text, txtPassword.Text)
End Sub
</script>

<form runat="server">
<asp:Panel ID="pnlLogin" runat="server">
UserName: <asp:TextBox ID="txtUserName" runat="server"/><br>
Password: <asp:TextBox ID="txtPassword" TextMode="password"
runat="server"/><br>
<asp:Button ID="btnLogin" OnClick="Login" Text="LOGIN" runat="server"/>
</asp:Panel>

<asp:Panel ID="pnlShowMsg" runat="server">
<asp:Label ID="lblMessage" runat="server"/>
</asp:Panel>
</form>

When the ASPX page loads for the first time, users see the 2 TextBoxes.
When a user enters his UserName & Password, assuming that the UserName
& Password exists in the database table, after executing the following
code line in the Page_Load sub

boUserDetails = boUser.GetDetails(????)

the Label "lblMessage" should display a message but I can't figure out
how to pass the ID (corresponding to the UserName & Password entered by
the user) to the "GetDetails" function which expects an integer ID
parameter under the class named "User". For e.g. if the ID
corresponding to the UserName & Password entered by the user is, say, 5
then the GetDetails line in the Page_Load sub should evaluate to

boUserDetails = boUser.GetDetails(5)

Can someone please tell me how do I pass the ID value to the
"GetDetails" function after the user enters a UserName & Password in
the 2 TextBoxes?

Thanks,

Arpan

Sep 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3029
by: Neal Coombes | last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for better from the unmoderated groups: -------- Original Message -------- Subject: Return appropriately by value, (smart)...
16
1967
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
15
2783
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
12
4103
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
3
2338
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
12
3767
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. ...
20
3560
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
6
1882
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document...
7
10290
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
6
2392
KoreyAusTex
by: KoreyAusTex | last post by:
If anyone can help me figure out the what the missing return statements are, I think it might be the fact that I need to add a return false in the getValue()? import java.util.*; public class...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.