cmd = new SQLiteCommand();
...
if (Convert.ToInt32(cmd.ExecuteScalar()) == 0)
goto doClose;
else
cmd.CommandText = sql;
reader = cmd.ExecuteReader(); // this is line 182, check the exception details below
更多: 我得睡覺了。下面是代碼源(我的GitHub回購),如果有人可以看看它? [email protected]:tomxuetoy/WPF_startPrograms.git爲什麼我不能直接在C#中編譯表達式和null?
上面是我的代碼,它可以正常工作。在我的情況下,cmd.ExecuteScalar()
將由於SQLite
表不存在而返回null。 我試圖改變它像之下,但失敗:
if (cmd.ExecuteScalar() == null)
所以,我想知道爲什麼我不能COMPRE表達(null
返回)和null
直接? 謝謝!
更: 下面的人都試過了,但同樣的結果:不能工作
if (cmd.ExecuteScalar() == DBNull.Value)
or
if (cmd.ExecuteScalar() is DBNull)
下文中詳細說明被複制的例外,但也有一些中國字...
System.Windows.Markup.XamlParseException occurred
HResult=-2146233087
Message=對類型「MultiStart.MainWindow」的構造函數執行符合指定的綁定約束的調用時引發了異常。
Source=PresentationFramework
LineNumber=0
LinePosition=0
StackTrace:
在 System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
InnerException: System.Data.SQLite.SQLiteException
HResult=-2147467259
Message=SQLite error
no such table: testTable
Source=System.Data.SQLite
ErrorCode=-2147467259
StackTrace:
在 System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
在 System.Data.SQLite.SQLiteCommand.BuildNextCommand()
在 System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
在 System.Data.SQLite.SQLiteDataReader.NextResult()
在 System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
在 System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
在 System.Data.SQLite.SQLiteCommand.ExecuteReader()
在 MultiStart.MainWindow.dbOp(dowhat dw) 位置 c:\Users\Administrator\Desktop\WPF_startPrograms\WpfApplication2\WpfApplication2\MainWindow.xaml.cs:行號 182
在 MultiStart.MainWindow.DataBinding() 位置 c:\Users\Administrator\Desktop\WPF_startPrograms\WpfApplication2\WpfApplication2\MainWindow.xaml.cs:行號 43
在 MultiStart.MainWindow..ctor() 位置 c:\Users\Administrator\Desktop\WPF_startPrograms\WpfApplication2\WpfApplication2\MainWindow.xaml.cs:行號 36
InnerException:
定義「失敗」 –
這是一個'goto'聲明嗎? – rene
你可以。什麼不工作? – shovavnik