我有這樣一段代碼:錯誤而在讀者致電變量
while (reader.Read())
{
count++;
string Text = (String.Format("{0}", Object.Equals(Variables.buffering, reader.GetValue(0))));
List<string> mystring = new List<string>();
mystring.Add(Text);
if (Convert.ToBoolean(Text))
{
string myText = new TextRange(mainWindow.richtextbox2.Document.ContentStart, mainWindow.richtextbox2.Document.ContentEnd).Text;
var str = Regex.Replace(myText, @"(|\r?\n)\1+", "$1", RegexOptions.Multiline);
mainWindow.Dispatcher.Invoke(new Action(() =>
mainWindow.richtextbox2.Document.Blocks.Add(new Paragraph(new Run("hello")))));
string text = "s";
mainWindow.WriteSerial(text);
Console.WriteLine(Text);
}
}
foreach (string element in mystring)
{
Console.WriteLine(element);
}
這是爲什麼我在foreach循環的MyString中有一個錯誤:
Error 2 The name 'mystring' does not exist in the current context
*這是另一種遇到的問題。請忽略前一個。
請添加您收到錯誤消息。 –
沒有錯誤。但它並沒有在那裏顯示「你好」字符串 – iaskyou
我不確定在你獲得RowCount後你要做什麼。驗證你的RowCount變量是否包含正確的行數,你應該很好。你爲什麼要調用reader.GetValue(0)?此外,您當然不應該試圖從您的數據訪問代碼寫入您的窗口。 –