C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




login Form problem


Posted Date: 27 Feb 2008      Total Responses: 3

Posted By: shahin pathan       Member Level: Silver     Points: 2


hi
Me new 2 VB.net i used VS 2005 version 8.0 and .NET Framework 2.0 and Microsoft SQL Enterprise Manager Microsoft Corporation Version: 8.0

i work on web application on canteen management in ASP.net and scripting in VB.net
if need code for login i have login form and login table like as follow
Userid Name Password Category
00001111 Shahin abc Emp
00002222 Sameer abc Emp
C001 Alfa can Can
C002 Suraj can Can

if i do login as Employee then it should redirect me 2 EmpLunch.aspx
if i do login as Canteen then it shoul redirect me 2 Lunchdinner.aspx
otherwise it prompt login failed

my code is as follow


Partial Class _Default
Inherits System.Web.UI.Page
Dim adp As SqlDataAdapter
Dim ds As New DataSet
Dim cmd As New SqlCommand
Dim con As SqlConnection
Dim str As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim s As String
If Not IsPostBack Then
s = "select * from Login"
Dim adp As New SqlDataAdapter(s, con)
End If
End Sub
Public Function GetConnection()
con = New SqlConnection("Server = 127.0.0.1;database = dbcanteen;uid = sa;pwd = ;")
Return con
End Function

Protected Sub btnlogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnlogin.Click
con = GetConnection()
str = "select * from login where Name='" + txtid.Text + "' and password='" + txtpwd.Text + "'and Category='" + "ddl.SelectedItem.ToString'"
Dim da As SqlDataAdapter = New SqlDataAdapter(str, con)
con.Open()
Dim ds As New Data.DataSet
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
Session("Username") = ds.Tables(0).Rows(0).Item(1)
Session("PWD") = ds.Tables(0).Rows(0).Item(2)
Response.Redirect("Emplunch.aspx")
Else
Response.Write("Unsuccessful login!!! Try again.")
End If
If ds.Tables(0).Rows.Count > 0 Then
Session("Username") = ds.Tables(0).Rows(0).Item(1)
Session("PWD") = ds.Tables(0).Rows(0).Item(2)
Response.Redirect("Lunch Dinner Form.aspx")
Else
Response.Write("Unsuccessful login!!! Try again.")
End If
End Sub
End Class

Plz help me its urgent
and thanks in advance






Responses

Author: Er. Ram Singh    27 Feb 2008Member Level: GoldRating:     Points: 2
protected void Sign_In(object sender, ImageClickEventArgs e)
{
try
{

Connection con = new Connection();
DataTable dt = new DataTable();

string str = "select * from LOGIN where LOGIN_USER_NAME= '" + Txt_User_Name.Value + "'" + " AND LOGIN_PASSWORD='" + Txt_Password.Value + "'";
dt = con.getDataTable(str);
Session["reg_id"] = dt.Rows[0]["REG_ID"].ToString();
Session["user"] = dt.Rows[0]["LOGIN_USER_NAME"].ToString();

Response.Redirect("../Registration/summary.aspx?regid=" + dt.Rows[0]["REG_ID"] + "&field=" + dt.Rows[0]["LOGIN_FIELD"] + "&user=" + Txt_User_Name.Value);

}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}


Author: swastik nath    27 Feb 2008Member Level: SilverRating:     Points: 2
For the button click event verify if the username and password are valid then use another select statement to retrieve the Category from the database.
next use IF condition to redirect the user to emplunch.aspx form if his category is employee
or redirect it to Lunchdinner.aspx

do revert back to me if you have any concerns.

regards,
Swastik Nath.


Author: swastik nath    27 Feb 2008Member Level: SilverRating:     Points: 2
Hi shahin,
Let me tell you exactly what I did..
I created 3 forms ..
Form 1=login.aspx.
Form 2 = emplunch.aspx
Form 3= lunchdinner.aspx

Now I put 3 controls on login.aspx.
One textbox for username.
One textbox for password.
One button for checking functionality.

In button click event I wrote the following code which is very simple to understand ..


Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New SqlConnection
con.ConnectionString = "server=ibm37;database=tempdb;user id=sa;pwd=sa"
Dim cmd As New SqlCommand("select category from tblcanteen where userid=(select userid from tblcanteen where name='" & TxtName.Text & "' and password='" & TxtPassword.Text & "')", con)
Dim dr As SqlDataReader
con.Open()
dr = cmd.ExecuteReader
If dr.Read Then
If dr.Item("category").ToString = "emp" Then
Response.Redirect("EmpLunch.aspx")
Else
Response.Redirect("Lunchdinner.aspx")
End If
Else
LblMessage.Text = "invalid Username/Password"
End If

con.Close()

End Sub



I am using userid as it's unique for every employee and depending upon his login info I am redirecting him to different forms.
The userid will be retrieved by the select statement only if the username and password match.
I hope your query is quite clear now..

Revert back to me if you have any concerns.

Regards,
Swastik Nath.



Post Reply
You must Sign In to post a response.
Next : Dymaic website
Previous : Sample program with example for Delegate
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

conference calls

Contact Us    Privacy Policy    Terms Of Use