我想从这个方法中返回一个变量。是的,我确实将其设为静态字符串。并试图返回 Messagebox.Show 所在的变量。我什至有一个相等的变量并试图返回它。但我似乎无法从 while 括号内返回。而且我无法让括号外的变量返回。该怎么办?该代码使用 MessageBox 工作,但我需要字符串变量。
static void rsnREAD(string dbTbl)
{
OleDbConnection machStopDB = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + @"C:\Users\sgarner\Google Drive\Visual Studio 2012\Write_to_db\Write_to_db\Machine_Stop.accdb");
//string sDate;
//sDate = DateTime.Now.ToString("MM/dd/yyy HH:mm:ss");
string str = "SELECT LAST(REASON) AS lastREASON FROM "+dbTbl+"";
OleDbCommand rdCmd = new OleDbCommand(str, machStopDB);
try
{
machStopDB.Open();
OleDbDataReader reader = rdCmd.ExecuteReader();
while (reader.Read())
{
MessageBox.Show(reader[0].ToString());
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
machStopDB.Close();
}
machStopDB.Close();
}