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
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
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
DBConnection abcd = new DBConnection();
MessageBox.Show(abcd .logidprop);
--------
in this case class return null value