Click here to Skip to main content
15,914,327 members
Please Sign up or sign in to vote.
2.09/5 (4 votes)
See more:
Hello Experts .

Login Form Code :

C#
con.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * From Admin Where EmployeeID = '" + LogId.Text.Trim() + "' AND Category = '" + CbCat.SelectedItem.ToString() + "' AND Designation = '" + CbDesignationAdmin.SelectedItem.ToString() + "' AND FinYear1 = '" + CbFinYr1.SelectedItem.ToString() + "' AND FinYear2 = '" + CbFinYr2.SelectedItem.ToString() + "' AND Emp_Password = '" + Password.Text.Trim() + "'  ", con);

OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
if (dt.Rows.Count == 0)
{
   MessageBox.Show("Wrong Login Id And Password ?");
   return;
}
else
{
   MessageBox.Show("Mr " + dt.Rows[0][4].ToString() + " :: You are Successfully Login ");
   MasterAdminForm maf = new MasterAdminForm();
   maf.Show();
   this.Hide();
}


New Form Open Code :
C#
con.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * From Admin ", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
if (dt.Rows.Count != 0)
{
   label1.Text = "Welcom Mr :  " + dt.Rows[0][3].ToString();
   label1.BackColor = Color.Black;
   label1.ForeColor = Color.White;
}


Here is problem in AdminMasterForm I Show Value In For hard core value

But in New Form It Show problem For fatching table Value Onthe basic of specific Id Like Admin .

C#
query = "SELECT * From Admin Where EmployeeID = '"+ LoginId.Text.ToString()+"' "

Like This

[edit]Code block added and indexation reduced[/edit]
Posted
Updated 18-Feb-14 5:12am
v5
Comments
ZurdoDev 18-Feb-14 7:00am    
How can we help?
Rohit85 18-Feb-14 7:05am    
Dear problem i m doing with window forms ............two different window i m unable to display table information in specific forms whic will be open
ZurdoDev 18-Feb-14 7:11am    
Why can't you display it?
Rohit85 18-Feb-14 9:29am    
problem to fatch table information according to login id but i m unable to find login id in New form which is opened
ZurdoDev 18-Feb-14 9:32am    
You did a select * from admin without any where clause. You need to be much more clear as to where you are stuck.

Hi Rohit,

As per your above question here it is not too much clear point that what you are exactly doing and what happened?

Ok but up to my understanding On the LOG in form just put the entered log in ID in session var and use that var to load further pages or respective data.

and here put your error what you are facing with stack trace.

Warm Regards,
Coder.
 
Share this answer
 
Comments
Krunal Rohit 18-Feb-14 10:28am    
How come Session works in Forms Applications ?
-KR
Killer Coder 19-Feb-14 8:50am    
Yap sure, I haven't noticed that you are talking about windows form!!!
I mean you have to use the properties as like of application level variable.
e.g.
Just create a static class which contains the required properties to store your logged in user ID & use this property on other page to fetch the value.

public static class MyGlobals
{
public static string LoggedUserId = "A00123";
}

public class YourClass
{

private void Method1()
{
//in below UserId you will get logged in user ID.
string UserId = MyGlobals.Global1;
//etc
}
}

Try it...:)
You can save the username in a static variable, so that you can access it from next form easily.

in the second form declare static Property
public static string LoginName {get; set;}

then in login form On button Ok /Login Click Event
form2.LoginName= LoginId.Text;

Now you can write your query in second form as
query = "SELECT * From Admin Where EmployeeID = '"+ LoginName +"' "
 
Share this answer
 
As you have not described your problem correctly, I came to this conclusion from your subject that you're passing the data between forms.

Regardless of your problem, there are 2 ways of doing that (basics of C#):
1.) Pass the values through constructor
2.) Make a property (get; set;) and call that by instance of the particular form

Here I'm showing you how to pass the data using ctor.
First Form
C#
button_click(...)  // Button Click Event
{
    string userName = "admin";
    SecondForm sf = new SecondForm(userName);
    sf.Show();
}

Second Form
C#
string userName;
public SecondForm(string userName)   // Ctor of second form
{
    this.userName = userName;
    lbl.Text = userName;
}


-KR
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900