public SQLiteCommand SQLiteCommand;
public SQLiteConnection SQLiteConnection;
定義的兩變數,在第一次使用時正常初始化和賦值,使用正常。
SQLiteCommand = new SQLiteCommand();
SQLiteCommand.Connection = SQLiteConnection;
SQLiteCommand.CommandText = SQLstring;
SQLiteDataReader dr = SQLiteCommand.ExecuteReader();
listView2.BeginUpdate();
listView2.Clear();
while (dr.Read())
{
ColumnHeader Col = new ColumnHeader();
Col.Text = dr["Name"].ToString();
Col.TextAlign = HorizontalAlignment.Center;
listView2.Columns.Add(Col);
}
第二次賦值時就出錯,請各位老師幫忙指點一下,謝謝了!
SQLstring = string.Format("SELECT * FROM {0}", listBox1.SelectedItem.ToString());
SQLiteCommand.CommandText = SQLstring; ////這句出錯
//SQLiteCommand = new SQLiteCommand(); ////如果重新初始化就能正常,但是應該能賦值的啊
SQLiteCommand.Connection = SQLiteConnection;
dr = SQLiteCommand.ExecuteReader();
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/284528.html
標籤:C#
上一篇:例外System.ArgumentOutOfRangeException”(位于 mscorlib.dll 中)
下一篇:C# as轉換問題
