Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello all,


I have 2 forms in my project (Login form, address form).

I need to return my data in SQL server 2005, in login table (Username,Password and Permission). how can I return result in table login to table address. I use class, but when I call class result get me null values
I'm trying to accomplish result to address form by using class if the login is successful, I must show the address form and close the Login form.so return user name and password in address form. so I have this class ConnectionClass
-------------------------------

login form


C#
connetionString = "Data Source=test;Initial Catalog=University;Integrated Security=True"; 
firstSql = "SELECT * FROM Login ";
connection = new SqlConnection(connetionString);
string userText = txtUsr.Text;
string passText = txtPassword.Text;

try {
 connection.Open();
command = new SqlCommand(firstSql, connection);
adapter.SelectCommand = command;
adapter.Fill(ds, "First Table");
adapter.Dispose();
command.Dispose();
connection.Close();


for (j = 0; j <= ds.Tables[0].Rows.Count - 1; j++)
{
string s1 = Convert.ToString(ds.Tables[0].Rows[j].ItemArray[1].ToString());
string s2 = Convert.ToString(ds.Tables[0].Rows[j].ItemArray[2].ToString());
string s3 = Convert.ToString(ds.Tables[0].Rows[j].ItemArray[3].ToString());
if ((string)s1 == txtUsr.Text && (string)s2 == txtPassword.Text && (string)s3 == "admin") {

        ConnectionClass conobject = new ConnectionClass();
 s4 = (ds.Tables[0].Rows[j].ItemArray[4].ToString());
conobject.Setusernameprop(s1);
conobject.Setpasswordprop(s2);
conobject.Setlogidprop(s4);
addressform AdFor = new addressform ();
add.show();
}
else
{
}

catch (Exception ex)
{MessageBox.Show(ex.Message);}


-----------------
ConnectionClass code

C#
public class ConnectionClass
{
public  string Getusernameprop()
{return usernameprop;}

 public void Setusernameprop(string uName) 
{usernameprop = uName;}

 public string passwordprop = string.Empty;
 public string Getpasswordprop() 

{ return passwordprop;}


 public void Setpasswordprop(string pAssword)
{passwordprop = pAssword;}

public string logidprop = string.Empty;
public string Getlogidprop()
{return logidprop;}

 public void Setlogidprop(string iDLog)
{logidprop = iDLog;}
}
---------------------------------
address form

I link with address table

C#
DBConnection abcd = new DBConnection();
MessageBox.Show(abcd .logidprop);

--------
in this case class return null value
Posted
Updated 6-Aug-12 23:25pm
v2

1 solution

Hello,
Change your code as per given below.


address form
C#
public ConnectionClass abcd = new ConnectionClass();

public addressform ()
{
    InitializeComponent();
}

private void Form_Load(object sender, EventArgs e)
{
    MessageBox.Show(abcd.logidprop);
}


login form
Old code
C#
addressform AdFor = new addressform ();
add.show();

New code
C#
addressform AdFor = new addressform ();
adFor.abcd = conobject;
add.show();
 
Share this answer
 
Comments
Adam_adam 7-Aug-12 11:24am    
Thanks so much but is is same problem

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