I have a WinForm,
I am have added command line functions as so-
foreach (string arg in args)
{
if (arg == "-id")
{
string u = "";
ADODB.Connection ADconn = new ADODB.Connection();
string connstr = "db connection string";
ADconn.ConnectionString = connstr;
object recs;
ADODB.Recordset rs = new ADODB.Recordset();
ADconn.Open(connstr);
string qry = string.Format("Select ID from TABLE where NO = '" + args[counts + 1] + "'");
rs = ADconn.Execute(qry, out recs, 0);
for (; !rs.EOF; rs.MoveNext())
{
string test = rs.Fields["column"].Value.ToString();
u = test;
}
}
counts = counts + 1;
}
Therefore args[counts + 1] is whatever variable the user input in the command line after -id. I need to use this value later on in my code however how can I do this?
One option is to create a class with static properties that encapsulate the command line arguments, e.g.
Initialize the values in your main() routine. You can then reference them anywhere in your program like