I
IndigoMontoya
Guest
I am passing one variable to a method and running a query against a database. The database query will then return 4 variables, that I need to be able to access from anywhere within my class. I do not want to set them as static variables as the values could potentially change. What would be the best plan of attack for me to return a, b, c and d from my GetDBData() procedure?
static void Main(string[] args)
{
double AN;
var keepHostOptions = false;
while (true)
{
Console.WriteLine("Please Input The Number:");
string an = Console.ReadLine();
if (double.TryParse(an, out AN) == true)
{
GetDBData(an);
//Need to be able to access the variables a, b, c, d from here
}
else
{
Console.WriteLine("Please Input A Valid Value!");
}
}
public static string GetDBData(string an)
{
string a;
string b;
string c;
string d;
using (var ctx = new ClientContext(url))
{
var web = ctx.Web;
List list = web.Lists.GetByTitle(site);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = string.Format("");
//ListItemCollection items = list.GetItems(camlQuery);
//ctx.Load(list);
//ctx.Load(items);
//ctx.ExecuteQuery();
var listItemCollection = list.GetItems(camlQuery);
ctx.Load(listItemCollection, eachItem => eachItem.Include(item => item, item => item["a"], item => item["b"], item => item["c"], item => item["d"]));
ctx.ExecuteQuery();
foreach(ListItem listItem in listItemCollection)
{
a = listItem["a"].ToString();
b = listItem["b"].ToString();
c = listItem["c"].ToString();
d = listItem["d"].ToString();
}
}
}
Continue reading...
static void Main(string[] args)
{
double AN;
var keepHostOptions = false;
while (true)
{
Console.WriteLine("Please Input The Number:");
string an = Console.ReadLine();
if (double.TryParse(an, out AN) == true)
{
GetDBData(an);
//Need to be able to access the variables a, b, c, d from here
}
else
{
Console.WriteLine("Please Input A Valid Value!");
}
}
public static string GetDBData(string an)
{
string a;
string b;
string c;
string d;
using (var ctx = new ClientContext(url))
{
var web = ctx.Web;
List list = web.Lists.GetByTitle(site);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = string.Format("");
//ListItemCollection items = list.GetItems(camlQuery);
//ctx.Load(list);
//ctx.Load(items);
//ctx.ExecuteQuery();
var listItemCollection = list.GetItems(camlQuery);
ctx.Load(listItemCollection, eachItem => eachItem.Include(item => item, item => item["a"], item => item["b"], item => item["c"], item => item["d"]));
ctx.ExecuteQuery();
foreach(ListItem listItem in listItemCollection)
{
a = listItem["a"].ToString();
b = listItem["b"].ToString();
c = listItem["c"].ToString();
d = listItem["d"].ToString();
}
}
}
Continue reading...