我在许多教程中看到,通过使用变量和Parameters.Add来构造sql语句
public void updateStudent(String @studentID, String @firstName, String @lastName)
{
SQLiteCommand command = conn.CreateCommand();
command.CommandText = "UPDATE Students SET firstName = @firstName, lastName = @lastName WHERE studentID = @studentID";
command.Parameters.Add(new SQLiteParameter("@studentID", @studentID));
command.Parameters.Add(new SQLiteParameter("@firstName", @firstName));
command.Parameters.Add(new SQLiteParameter("@lastName" , @lastName));
command.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud)
我们为什么不用
string.Format("Update Students SET firstName = '{0}', lastName = '{1}...", @firstName, @lastname)
Run Code Online (Sandbox Code Playgroud)
任何好处?
现在我使用C#中的方法将SQLite数据库中的表读入DataTable,但我想将所有表发送到其他对象中.
所以我认为我必须使用DataSet来组合所有DataTable并将其作为参数发送给对象.
是否有方法可以轻松读取SQLite数据库中的所有表到DataSet?或者我必须从SQLite数据库读取所有表到DataTable的每个表并手动组合到DataSet?
我尝试使用SQLite DLL,一切都很好.我有一个关于SQLite.dll的问题是v2.xx不能用于我的项目.NET v4.
所以我在这个网站上找到了创建App.config的解决方案,其中包含这样的信息
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
Run Code Online (Sandbox Code Playgroud)
所以,解决方案的工作.我可以正确使用SQLite,但编译器总是显示这样的消息

有什么建议?