sqlite使用出错了,不知道哪里问题

shdhsdd 2014-01-08 02:25:32
我想做一个登陆的功能
我用资源设置连接数据库的:


链接字符串是:
public static string connectionString = Constant.DBConnUrl;


public static DataTable ExecuteDataTable(string sql, SQLiteParameter[] parms)
{
DataTable data = new DataTable();
SQLiteConnection conn = new SQLiteConnection(connectionString);
SQLiteCommand command = new SQLiteCommand(sql, conn);

if (parms != null)
{
command.Parameters.AddRange(parms);
}

SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
adapter.Fill(data);

return data;
}


DAL层是:
public class UserDAL
{

public string UserPwdByUserName(string userName)
{
SQLiteParameter parm = new SQLiteParameter
("@userName", SqlDbType.VarChar);
parm.Value = userName;
string pwd = (string)SQLiteDBHelper.ExcuteScalar("select UserPwd from T1 where UserName=@userName", parm);
return pwd;
}
}

BLL:
SJ.DAL.UserDAL d = new SJ.DAL.UserDAL();
public string UserPwdByUserName(string userName)
{
string pwd = d.UserPwdByUserName(userName);
return pwd;
}


表示层是:
private void Login1_Click_1(object sender, RoutedEventArgs e)
{
string pwd = ub.UserPwdByUserName(UserName.Text.Trim().ToLower());
if (string.IsNullOrEmpty(pwd))
{
MessageBox.Show("无此用户");
return;
}
else
{
if (pwd.ToLower() == this.Pwd.Text.Trim().ToLower())
{
MessageBox.Show("成功");
Window1 i = new Window1();
i.Show();
this.Hide();

}
else
{
MessageBox.Show("失败");
}


}

检查数据库类:
public class DBCheck
{
public static Boolean InitDB()
{
bool success = true;
if (!DBExsist())//如果DB文件不存在,生成DB文件,及内部表结构
{
try
{
SQLiteConnection.CreateFile(Constant.DBLoc);
}
catch (Exception e)
{
success = false;
return success;
}
success = CreateTable(Constant.DBDDL);
}
return success;
}

private static Boolean DBExsist()
{
if (!File.Exists(Constant.DBLoc))
{
return false;
}
return true;
}

private static bool CreateTable(String ddl)
{
int val = 0;
val = SQLiteDBHelper.ExecuteNonQuery(ddl, null);
if (val != 0)
{
return false;
}
return true;
}
}

DB.sqlite:T1表,id,UserName,UserPwd。

在运行的时候提示SQL logic error or missing database
no such table:T1;

...全文
1193 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
OSMeteor 2014-01-10
  • 打赏
  • 举报
回复
引用 8 楼 hanwb2010 的回复:
sqlite 数据库连接字符串为: Data Source=数据库路径;Pooling=true;FailIfMissing=false;password=密码 没有密码连接字符串:Data Source=数据库路径;Pooling=true;FailIfMissing=false; 而你的连接字符串竟然是Data Source=db.sqlite,数据库路径都没有指定,肯定报找不到数据库错误。
good
wb_han 2014-01-10
  • 打赏
  • 举报
回复
sqlite 数据库连接字符串为: Data Source=数据库路径;Pooling=true;FailIfMissing=false;password=密码 没有密码连接字符串:Data Source=数据库路径;Pooling=true;FailIfMissing=false; 而你的连接字符串竟然是Data Source=db.sqlite,数据库路径都没有指定,肯定报找不到数据库错误。
lfqsy 2014-01-08
  • 打赏
  • 举报
回复
缺少dll??
失落的神庙 2014-01-08
  • 打赏
  • 举报
回复
/// <summary>
        /// 打开数据库连接
        /// </summary>
        /// <returns></returns>
        private bool ConnOpen()
        {
            if (conn == null)
            {
                SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder();
                connstr.DataSource = DataPath;
                conn = new SQLiteConnection();
                conn.ConnectionString = connstr.ToString();
            }

            while (conn.State ==
                (ConnectionState.Connecting
                | ConnectionState.Executing
                | ConnectionState.Fetching))
            { Thread.Sleep(100); }
            if (conn.State == ConnectionState.Open)
            { return true; }
            try
            { conn.Open();  return true; }
            catch (Exception ex) { return false; }
        }
失落的神庙 2014-01-08
  • 打赏
  • 举报
回复
connstr.DataSource = Application.StartupPath + "\\Db"; 试试这样用
shdhsdd 2014-01-08
  • 打赏
  • 举报
回复
引用 3 楼 wawd74520 的回复:
[quote=引用 2 楼 wyd1520 的回复:] SQL logic error or missing database 提说了呀没有数据库。。。
soga 英文不好 估计他路径写错了[/quote] 不是的,路径是对的
失落的神庙 2014-01-08
  • 打赏
  • 举报
回复
引用 2 楼 wyd1520 的回复:
SQL logic error or missing database 提说了呀没有数据库。。。
soga 英文不好 估计他路径写错了
本拉灯 2014-01-08
  • 打赏
  • 举报
回复
SQL logic error or missing database 提说了呀没有数据库。。。
失落的神庙 2014-01-08
  • 打赏
  • 举报
回复
没有T1 这个表

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧