我想在MonoDevelop中創建一個簡單的登錄窗口,但只要點擊按鈕就會崩潰。用SQLite登錄屏幕崩潰
使用以下命令:SqliteConnection.CreateFile("*.sqlite");
我能確定它運行到第26行,但不是28
這裏是我的代碼:
using System;
using Gtk;
using Mono.Data.Sqlite;
using System.Data;
namespace BB
{
public partial class BBLogin : Gtk.Window
{
public BBLogin() :
base (Gtk.WindowType.Toplevel)
{
this.Build();
}
private void btnLoginOnClick (object sender, EventArgs e)
{
SqliteConnection conn = new SqliteConnection();
conn.ConnectionString = "Data Source=BBUser.sqlite;Version=3;";
SqliteCommand command = new SqliteCommand();
command.CommandText = ("SELECT UserName FROM T_test WHERE [email protected] AND [email protected]");
command.Parameters.AddWithValue ("@UserName", txtUserName.Text);
command.Parameters.AddWithValue ("@Password", txtPassword.Text);
conn.Open();
/*line 26*/ SqliteConnection.CreateFile("failsafe0.sqlite");
object result = command.ExecuteScalar();
SqliteConnection.CreateFile("failsafe1.sqlite");
conn.Close();
SqliteConnection.CreateFile("failsafe2.sqlite");
string userNameLogin = Convert.ToString(result);
SqliteConnection.CreateFile("failsafe3.sqlite");
if (userNameLogin != "")
{
SqliteConnection.CreateFile("success.sqlite");
/*MessageDialog md = new MessageDialog ("Username was correct!");
md.Run();
md.Destroy();*/
}
else
{
SqliteConnection.CreateFile("failed.sqlite");
/*MessageDialog md = new MessageDialog ("Username or password is incorrect!");
md.Run();
md.Destroy();*/
}
}
}
}
,這裏是完整的異常詳細信息:
Gtk#回調委託中的異常 注意:應用程序可以使用GLib.ExceptionManager.UnhandledException來處理異常。 System.Reflection.TargetInvocationException:調用的目標引發了異常。 ---> System.InvalidOperationException:沒有與此命令關聯的連接 at Mono.Data.Sqlite.SqliteCommand.InitializeForReader()[0x00000] in:0 at Mono.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior) [0x00000] in:0 at Mono.Data.Sqlite.SqliteCommand.ExecuteScalar()[0x00000] in:0 at BB.BBLogin.btnLoginOnClick(System.Object sender,System.EventArgs e)[0x0006c] in/home/(包裝託管到本機)System.Reflection.MonoMethod:InternalInvoke(System.Reflection.MonoMethod,object,object [],System.Exception &) at System。回到頂端這篇文章中的信息適用於: Reflection.MonoMethod.Invoke(System.Object obj,BindingFlags invokeAttr,System.Reflection.Binder聯編程序,System.Object []參數在System.Reflection.MonoMethod.Invoke(System.Object obj,BindingFlags invokeAttr,System.Reflection。)中的內部異常堆棧跟蹤--- 結束。在System.Reflection.MethodBase.Invoke(System.Object obj,System.Object []參數)[0x00000]中的[]中的[0x00000] 0 at System.Delegate.DynamicInvokeImpl(System.Object [] args)[0x00000] in:0 at System.MulticastDelegate.DynamicInvokeImpl(System.Object [] args)[0x00000] in:0 at System.Delegate.DynamicInvoke (System.Object [] args)[0x00000] in:0 at GLib.Signal.ClosureInvokedCB(System.Object o,GLib.ClosureInvokedArgs args)[0x00000] in:0 at在GLib.SignalClosure.MarshalCallback(IntPtr raw_closure,IntPtr return_val,UInt32 n_param_vals,IntPtr param_values,IntPtr invocation_hint,IntPtr marshal_data)[0x00000]中的:0 在GLib.ExceptionManager.RaiseUnhandledException(System.Exception的E,布爾is_terminal) 在GLib.SignalClosure.MarshalCallback(IntPtr的raw_closure,IntPtr的RETURN_VAL,UInt32的n_param_vals,IntPtr的param_values,IntPtr的invocation_hint,IntPtr的marshal_data) 在Gtk.Application.gtk_main() 在Gtk.Application.Run() 在BB.MainClass.Main在/ home(System.String []參數)/基督教/ BB/BB /Program.cs:line 15
此致
Chris
非常感謝!這有助於:) – Chriswidell