Hi all,
Im not familiar with asp.net and both learning this and doing my final project of the year. So there are so many problems i faced.......

Here are one...........I want to display user detail information after he/she logod on. How can i codig this???????????????????

Any idea would be much appreciated.........^^

But its better to attach with source code....

Thanks............

Recommended Answers

All 10 Replies

man this is easy.
u logged in with a username and password.
u create a session and put in it ur username
then u make a query to retrive data from db using the session as ur condition.
ex.

select fname, lname from users where user_lognname = '" & session("id") & "'

I tried what you adviced me...........Here is my code........

This is for ViewStatus page, and there is only one datagrid in design.......

Imports System.Data.OleDb
Imports System.Data
Imports System.Data.SqlClient
Public Class ViewStatus
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim ds As New DataSet
Dim sda As OleDbDataAdapter
Dim strSQL As String
Dim strCon As String

strSQL = "SELECT * from NorthWindUsers where Password = '" & Session("Password") & "'"

strCon = "Provider=SQLOLEDB;data source=Batbayar;" & _
"User id=sa;password=sa;Initial Catalog=Northwind"

sda = New OleDbDataAdapter(strSQL, strCon)
sda.Fill(ds, "Customers")

DataGrid.DataSource = ds.Tables("Customers")
DataGrid.DataBind()
End Sub
End Class


My login page is the page what Paladine made for the novice........

These 2 pages are big problem to me.......My idea is after i logged in then go direct to ViewStatus page and retrieve detail data from database.........

Please you u possibe then make it right.....Apologize...............

thanks,^^

man i dont remember the database schema of northwind, sorry.

i want to ask u when the session("password") u put value in it?
second, as i said before put in the users table, new attribute and name it "loginname", it must be unique but not the primary key in the table.

then as u wrote open a connection and make a query but based on the loginname, not password. more security dude, dont put ur password in any tables.

here is the code:

strSQL = "SELECT * from NorthWindUsers where loginname = '" & tx1.text & "'"

tx1 is the text box for loginname in the login page.

hope i answer ur quetion

sam

Hey i tried.............But on the page of ViewStatus txt1.text couldnt work........Cause i declared it on page Login......So it isnt work as public......How can i make it to right???????????Please understand my poor knowledge about .net. I'm learning this for 2 months.......... :cheesy: .................................Also how can i create session and develop it suitable to my source code.....??????????? If you give me a little hint it would be much help to me..............

Thanks,,,,,,,,,,,,,,,,,,

bagi

man why u want to use txt1.text in another page, use it in the sign in page.
the signin.aspx.vb
write all ur codes here "underlaying code"

man why u want to use txt1.text in another page, use it in the sign in page.
the signin.aspx.vb
write all ur codes here "underlaying code"

session("userid") = txt1.text
now u create a session and its name is "userid"
u can use it in any page u want

Ok, i'll write all my code down here:

There are 2 pages. First: login, and second: see detail infromation with the ID you logged in. You can just copy, paste and run it.........^^


-----------------------------------------------------------------------------------
See detail information ::::

<HTML>
<HEAD>
<title>ViewStatus</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid" style="Z-INDEX: 101; LEFT: 176px; POSITION: absolute; TOP: 64px" runat="server"
Width="416px" Height="208px" BorderColor="#999999" BorderStyle="Solid" CellSpacing="2" BorderWidth="3px"
BackColor="#CCCCCC" CellPadding="4" ForeColor="Black">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#000099"></SelectedItemStyle>
<ItemStyle BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="Black"></HeaderStyle>
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<PagerStyle HorizontalAlign="Left" ForeColor="Black" BackColor="#CCCCCC" Mode="NumericPages"></PagerStyle>
</asp:DataGrid></form>
</body>
</HTML>

****************************

Imports System.Data.OleDb
Imports System.Data
Imports System.Data.SqlClient
Public Class ViewStatus
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim ds As New DataSet
Dim sda As OleDbDataAdapter
Dim strSQL As String
Dim strCon As String

strSQL = "SELECT * from NorthWindUsers where Password ='" & Session("password") & "' "
'" & Session("txtPassword.Text") & "'
strCon = "Provider=SQLOLEDB;data source=Batbayar;" & _
"User id=sa;password=sa;Initial Catalog=Northwind"

sda = New OleDbDataAdapter(strSQL, strCon)
sda.Fill(ds, "Info")

DataGrid.DataSource = ds.Tables("Info")
DataGrid.DataBind()
End Sub
End Class

-------------------------------------------------------------------------------------------

Login page:

<HTML>
<HEAD>
<title>Northwind Database Login</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<!-- <summary>
||||| Style Sheet |||||
</summary>
--><LINK title="standard" href="Styles.css" type="text/css" rel="stylesheet">
</HEAD>
<body>
<!-- ||||| Login Form ||||| -->
<form id="frmlogin" method="post" runat="server">
<table id="mainTable">
<tr>
<td>
<table class="t_border" id="loginTable" cellSpacing="15" cellPadding="0">
<tr>
<td><b>Login: </b>
</td>
<td><asp:textbox id="txtUserName" runat="server" width="160px"></asp:textbox><asp:requiredfieldvalidator id="rvUserValidator" runat="server" display="None" errormessage="You must supply a Username!"
controltovalidate="txtUserName"></asp:requiredfieldvalidator></td>
</tr>
<tr>
<td><b>Password: </b>
</td>
<td><asp:textbox id="txtPassword" runat="server" width="160px" textmode="Password"></asp:textbox><asp:requiredfieldvalidator id="rvPasswordValidator" runat="server" display="None" errormessage="Empty Passwords not accepted"
controltovalidate="txtPassword"></asp:requiredfieldvalidator></td>
</tr>
<tr>
<td align="center" colSpan="2"><asp:button id="cmdSubmit" runat="server" borderstyle="Solid" text="Submit"></asp:button></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table id="messageDisplay">
<tr>
<td><asp:validationsummary id="Validationsummary1" runat="server" width="472px" displaymode="BulletList"></asp:validationsummary></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<asp:label id="lblMessage" runat="server" width="288px" forecolor="#C00000" font-size="Medium"
font-italic="True" font-bold="True"></asp:label>
<!-- ||||| End of Form ||||| -->
</body>
</HTML>

****************************

Imports System.Web.Security ' |||||| Required Class for Authentication
Imports System.Data ' |||||| DB Accessing Import
Imports System.Data.SqlClient ' |||||| SQL Server Import
Imports System.Configuration ' |||||| Required for Web.Config appSettings ||||

Public Class Login
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents txtUserName As System.Web.UI.WebControls.TextBox
Protected WithEvents rvUserValidator As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
Protected WithEvents rvPasswordValidator As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents cmdSubmit As System.Web.UI.WebControls.Button
Protected WithEvents Validationsummary1 As System.Web.UI.WebControls.ValidationSummary
Protected WithEvents lblMessage As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Public Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click

If Page.IsValid Then ' ||||| Meaning the Control Validation was successful!
' ||||| Connect to Database for User Validation |||||
If DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()) Then
Session("Logged_IN") = "Yes"
'FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False) ' ||||| default.aspx Page!
Response.Redirect("ViewStatus.aspx")
Session("Password") = txtPassword.Text
Else
' ||||| Credentials are Invalid
lblMessage.Text = "Invalid Login!555"
End If
End If
End Sub
Function DBConnection(ByVal strUserName As String, ByVal strPassword As String) As Boolean
'<sumamry>
' ||||| Declare Required Variables
' ||||| Access appSettings of Web.Config for Connection String (Constant)
'</summary>
' ||||| This is the Connections Object for an SQL DB
Dim MyConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("strConn"))

'<sumamry>
' ||||| Create a OleDb Command Object
' ||||| Pass in Stored procedure
' ||||| Set CommandType to Stored Procedure
'</summary>

' ||||| To Access a Stored Procedure in SQL Server - Requires a Command Object
Dim MyCmd As New SqlCommand("sp_ValidateUser", MyConn)

MyCmd.CommandType = CommandType.StoredProcedure
' ||||| Create Parameter Objects for values passed in
Dim objParam1, objParam2 As SqlParameter
' ||||| Create a parameter to store your Return Value from the Stored Procedure
Dim objReturnParam As SqlParameter
'<sumamry>
' ||||| Add the parameters to the parameters collection of the
' ||||| command object, and set their datatypes (OleDbType in this case)
'</summary>
objParam1 = MyCmd.Parameters.Add("@UserName", SqlDbType.VarChar)
objParam2 = MyCmd.Parameters.Add("@Password", SqlDbType.VarChar)
objReturnParam = MyCmd.Parameters.Add("@Num_of_User", SqlDbType.Int)

' ||||| Set the direction of the parameters...input, output, etc
objParam1.Direction = ParameterDirection.Input
objParam2.Direction = ParameterDirection.Input
objReturnParam.Direction = ParameterDirection.ReturnValue ' Note RETURNVALUE
'' ||||| Set the value(s) of the parameters to the respective source controls
objParam1.Value = txtUserName.Text
objParam2.Value = txtPassword.Text

' ||||| Try, catch block!
Try
' ||||| Check if Connection to DB is already open, if not, then open a connection
If MyConn.State = ConnectionState.Closed Then
' ||||| DB not already Open...so open it
MyConn.Open()
MyCmd.ExecuteNonQuery()
End If
' ||||| Was the return value greater than 0 ???
If objReturnParam.Value < 1 Then
lblMessage.Text = "Invalid Login!"
Else
Return True
End If

' ||||| Close the Connection Closes with it
MyConn.Close()


Catch ex As Exception
lblMessage.Text = "Error Connecting to Database!"
End Try


End Function

End Class

****************************

In webconfig file:

<appSettings>
<add key="strConn" value="Data Source=(local);database=northwind;User id=sa;Password=sa;"/>
</appSettings>


<system.web>

****************************

Stored prucedure:

ALTER PROCEDURE dbo.sp_ValidateUser /* How it would appear in QUERY ANALYZER */
(
@UserName VARCHAR(50) = NULL,
@Password VARCHAR(50) = NULL,
@Num_of_User INT = 0
)
AS
SET @Num_of_User = (SELECT COUNT(*) AS Num_of_User
FROM NorthWindUsers
WHERE UserName = @UserName AND Password = @Password)
RETURN @Num_of_User

------------------------------------------------------------------------------------

Now you can see what im trying to make, where i make mistake.....much clear.....If you can make it shorter and more comprehensible than i did, then it would be BIG BIG BIG HELP TO ME......Please give me a hand...........~~

I must finish my project by next week...............

Thanks,...

bagi

man when u try to run the system, what is the error u got? can u post it so i know the problem coz the code seems to me alright.

man this session Session("txtPassword.Text") where u create it?

sam

Hi there,

I got no error....................But how i can declare that code????????????????Where should i put that code???????? Sorry i poor knowledge about .net since i novice^^...............If you can create for me simple login page and see detail page much easier than what i did, it would be good..............

thanks,

bagi

I HAVE WITH ME THE FULL CODE OF ASP.NET LOGIN USING VB.NET AND IF YOUR ARE INTRESTED TO HAVE IT........

MAIL ME AT:
adk_226@yahoo.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.