Мне очень нужна помощь относительно моего кодирования. В моем кодировании мне нужно использовать статические переменные для передачи значения между функциями, и я действительно не понимаю, как это сделать. Очень ценю, если кто-то может мне помочь в этом. Благодарю.Как передать параметр с помощью статической переменной?
static String TypeOfReport;
static DateTime DateOfExecution;
static DateTime StartDate;
static DateTime EndDate;
static int SpokeCode;
static void Main(string[] args)
{
DateTime start = System.DateTime.Now.AddMinutes(1);
Schedule.PeriodicSchedules schedule = new Schedule.PeriodicSchedules(start, Schedule.PeriodicSchedules.Frequency.Minutely);
schedule.Elapsed += new System.Timers.ElapsedEventHandler(GenerateReport);
schedule.Enabled = true;
Console.ReadLine();
}
static void GenerateReport(object sender, EventArgs e)
{
if (TypeOfReport == "BillingReport")
{
Schedule.PeriodicSchedules s = new Schedule.PeriodicSchedules(DateOfExecution, Schedule.PeriodicSchedules.Frequency.Minutely);
s.Elapsed += new System.Timers.ElapsedEventHandler(hell);
crRpt.Load("C:\\rptBilling.rpt");
ReportLogin(crRpt);
crRpt.SetParameterValue("@CollectionStartDate", StartDate);
crRpt.SetParameterValue("@CollectionEndDate", EndDate);
crRpt.SetParameterValue("@SpokeCode", SpokeCode);
}
}
static void ReportAccess()
{
SqlConnection thisConnection = new SqlConnection("data source=s3rosteam;initial catalog=ReportDB; integrated security=True; Pooling=False;");
SqlCommand thisCommand = null;
try
{
String strSQL = "SELECT TypeO fReport,DateOfExecution,StartDate,EndDate,SpokeCode FROM dbo.Schedule WHERE TypeOfReport ='" + TypeOfReport + "', DateOfExecution = '" + DateOfExecution + "'";
thisConnection.Open();
thisCommand = new SqlCommand(strSQL);
thisCommand.Connection = thisConnection;
thisCommand.CommandType = CommandType.Text;
using (SqlDataReader reader = thisCommand.ExecuteReader())
{
reader.Read();
StartDate = Convert.ToDateTime(reader["StartDate"]);
EndDate = Convert.ToDateTime(reader["EndDate"]);
SpokeCode = Convert.ToInt16(reader["SpokeCode"]);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
thisCommand.Dispose();
thisConnection.Close();
thisCommand.Dispose();
}
}
Вам не нужно передавать параметры при использовании глобальных переменных. –
Попробуйте прочитать [«StartDate»]. ToString() или readerGetString («VALUE»), по умолчанию считыватель данных возвращает объект. – Lloyd
@srahifah вы считали [параллельным] (http://www.ldoceonline.com/popup/popupmode.html?search_str=concurrent) выполнение? – ANeves