andrewmanuja
Well-known member
- Joined
- May 30, 2019
- Messages
- 75
- Programming Experience
- Beginner
Hi,
Thanks for the above respond.
Now, my requirement is to retrieve a single string value from the database based on the variable value I collected at the user login point.
Basically, I want to get the "costCentreCode" which relates to individual user and pass it to a textbox.
My class looks as below;
public class UserData
{
public static string userName;
public static string costCentreCode;
}
I have written a function to get the "costCentreCode" as below;
private void CallCostCentre()
{
SqlCommand cmd = new SqlCommand("SELECT costCentreCode FROM tbl_UserData WHERE userName= UserData.userName ", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
string costCentreCode = null;
if(dr.Read ())
{
UserData.costCentreCode = (string)dr[0];
}
dr.Close();
con.Close();
}
Note
con refers to connection string
Please find my original post of the question on below link
"Question - Store user login data in to a Class and reuse within the application"
I need two favors;
1. Whether the function I have written on the respective window form is correct?
2. How to call the "costCentreCode" value using the function elsewhere of the program/ or at least on the same window form?
Thank you very much in advance for your favorable comments.
Look forward to hearing from you.
Kind regards,
Andrew
Thanks for the above respond.
Now, my requirement is to retrieve a single string value from the database based on the variable value I collected at the user login point.
Basically, I want to get the "costCentreCode" which relates to individual user and pass it to a textbox.
My class looks as below;
public class UserData
{
public static string userName;
public static string costCentreCode;
}
I have written a function to get the "costCentreCode" as below;
private void CallCostCentre()
{
SqlCommand cmd = new SqlCommand("SELECT costCentreCode FROM tbl_UserData WHERE userName= UserData.userName ", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
string costCentreCode = null;
if(dr.Read ())
{
UserData.costCentreCode = (string)dr[0];
}
dr.Close();
con.Close();
}
Note
con refers to connection string
Please find my original post of the question on below link
"Question - Store user login data in to a Class and reuse within the application"
I need two favors;
1. Whether the function I have written on the respective window form is correct?
2. How to call the "costCentreCode" value using the function elsewhere of the program/ or at least on the same window form?
Thank you very much in advance for your favorable comments.
Look forward to hearing from you.
Kind regards,
Andrew