EDN Admin
Well-known member
Hello my friends:
I am looking for a best practice solution: And I am using this piece of sample code I wrote to illustrated the point.
I have this DataSet which returns two Variable as a parameter to Command/SQL Parameter Objects. The DataSet also gets data from the database based on the two parameters.
static DataSet LoadProfile()
{
return Database.GetUserProfile(UserID, UserName);
}
The problem is I want to be able to use the dataSet in multiple methods (other methods) but it seem my only option is to usevar or to simply invoke the DataSet (method) everywhere I need to use the DataSet. This code is in a Class.
Here is the code: The DataSet is LoadProfile().
public static string CreateGreeting()
{
string userFirstName = LoadProfile().Tables[0].Rows[0]["FirstName"].ToString();
string userLastName = LoadProfile().Tables[0].Rows[0]["LastName"].ToString();
Int16 intGetHour = Convert.ToInt16(DateTime.Now.Hour);
if ((intGetHour < 12) & (!string.IsNullOrEmpty(userLastName)))
{
return "Good Morning " + userFirstName + " " + userLastName;
}
else
{
return "Good Morning";
}
}
As I stated the Date Set uses UserID and UserName as parameter and returnsFirstName and LastName from the Datasabe. But as you can see I have to invoke theload profile each time.
Is there a simple or less redundant way to do this? Again, using the var does not work for me because it can only be used locally, this means I will have to use var every where I need the data set. Example:
var row = LoadProfile().Tables[0].Rows[0]
I will appreciate any help, I am still learning this stuff.
Synth
View the full article
I am looking for a best practice solution: And I am using this piece of sample code I wrote to illustrated the point.
I have this DataSet which returns two Variable as a parameter to Command/SQL Parameter Objects. The DataSet also gets data from the database based on the two parameters.
static DataSet LoadProfile()
{
return Database.GetUserProfile(UserID, UserName);
}
The problem is I want to be able to use the dataSet in multiple methods (other methods) but it seem my only option is to usevar or to simply invoke the DataSet (method) everywhere I need to use the DataSet. This code is in a Class.
Here is the code: The DataSet is LoadProfile().
public static string CreateGreeting()
{
string userFirstName = LoadProfile().Tables[0].Rows[0]["FirstName"].ToString();
string userLastName = LoadProfile().Tables[0].Rows[0]["LastName"].ToString();
Int16 intGetHour = Convert.ToInt16(DateTime.Now.Hour);
if ((intGetHour < 12) & (!string.IsNullOrEmpty(userLastName)))
{
return "Good Morning " + userFirstName + " " + userLastName;
}
else
{
return "Good Morning";
}
}
As I stated the Date Set uses UserID and UserName as parameter and returnsFirstName and LastName from the Datasabe. But as you can see I have to invoke theload profile each time.
Is there a simple or less redundant way to do this? Again, using the var does not work for me because it can only be used locally, this means I will have to use var every where I need the data set. Example:
var row = LoadProfile().Tables[0].Rows[0]
I will appreciate any help, I am still learning this stuff.
Synth
View the full article