gpt4 book ai didi

asp.net - 在 Asp.Net 中使用 SqLite

转载 作者:行者123 更新时间:2023-12-02 09:45:38 25 4
gpt4 key购买 nike

我正在尝试在我的 Asp.Net 中使用 SqLite。我在连接字符串 web.config 中有下面的代码

<add name="ConnectionStringName" connectionString="data source=MembersLastLogin3.s3db" providerName="System.Data.SQLite" />

这是运行查询的代码

public  int ExecuteNonQuery(string sql)
{
try
{
string con = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
SQLiteConnection cnn = new SQLiteConnection(con);
cnn.Open();
SQLiteCommand mycommand = new SQLiteCommand(cnn);
mycommand.CommandText = sql;
int rowsUpdated = mycommand.ExecuteNonQuery();
cnn.Close();
return rowsUpdated;
}
catch { throw; }
}
}

这个简单的查询

sql = "INSERT INTO LastLogin (MemId ) VALUES ('" + res + "');";
LocalDb.ExecuteNonQuery(sql);

但我收到错误“表 LastLogin 不存在”

我已经使用过 SqLitein .Net,但这是我第一次在 Asp.Net 中使用它,我确定该表存在,但似乎可以连接到它,我的问题在哪里? web.config 中的设置是否足够?有可用的教程吗?谢谢

最佳答案

我想你的文件db存储在asp.net网站的App_Data目录中。

所以只需尝试更改您的连接字符串:

<add name="ConnectionStringName" connectionString="data source=|DataDirectory|MembersLastLogin3.s3db" providerName="System.Data.SQLite" />

关于asp.net - 在 Asp.Net 中使用 SqLite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8197858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com