我创建了一个使用 sqlite数据库
的C#应用程序我的应用应该在系统帐户上运行。
当我在系统帐户上运行我的应用程序时,它运行得很好但是当应用程序开始使用sqlite时,它发送了一个错误,我的应用程序已关闭...
更新
错误附加在clsCon.con.State
我的代码:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication9
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void login_key_Click(object sender, RoutedEventArgs e)
{
//check connection is open . if it's close that and open again
if (clsCon.con.State == ConnectionState.Open)
clsCon.con.Close();
clsCon.con.Open();
// create a database object
DB DB_OBJECT = new DB();
//check user pass query
string result_query;
result_query = DB_OBJECT.check_user_pass(username.Text, password.Password);
MessageBox.Show(result_query);
clsCon.con.Close();
}
}
}
// --------------------------------
class clsCon
{
public static SQLiteConnection con = new SQLiteConnection("Data Source=Test.s3db");
public clsCon()
{
}
}
// --------------------------------
class DB
{
public string check_user_pass(string username, string password)
{
string string_result = "e1";
SQLiteCommand cmd = new SQLiteCommand();
String sSQL = "";
sSQL = "Select * from tbl_user Where username = '" + username + "'" + " AND password = '" + password + "'";
cmd.CommandText = sSQL;
cmd.Connection = clsCon.con;
SQLiteDataReader dr3;
dr3 = cmd.ExecuteReader();
int counter = 0;
while (dr3.Read())
{
counter++;
}
if (counter == 0) { string_result = "e1"; }
else { string_result = "success"; }
return string_result;
}
}