SQLite的问题,逃避某些字符 [英] SQLite issues, escaping certain characters

查看:121
本文介绍了SQLite的问题,逃避某些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作我的第一个数据库应用程序。这是一个使用SQLite数据库用C#编写一个WinForms应用程序。

I'm working on my first database application. It is a WinForms application written in C# using a SQLite database.

我已经遇到了一些问题,当撇号时,我的SQLite查询失败。这是我的查询的结构。

I've come across some problems, when a apostrophe is used, my SQLite query fails. Here is the structure of my queries.

string SQL = "UPDATE SUBCONTRACTOR SET JobSite = NULL WHERE JobSite = '" + jobSite + "'";

有关例如,如果一个撇号用于在工地变种,它抵消在命令中其他撇号,并且将失败。

For instance, if an apostrophe is used in the jobSite var, it offsets the other apostrophes in the command, and fails.

所以,我的问题是:

1。我怎么逃脱喜欢在上面的查询示例中的撇号和分号字符?

2。我需要什么字逃脱?我知道我应该逃脱撇号,还有什么危险?

感谢您的帮助!

推荐答案

而使用参数

有一个关于它的previous堆栈溢出的问题。

There is a previous stack-overflow question about it

添加参数SQLite中使用C#

如果你需要更多的功能,你还可以使用实体框架

if you need more functionality you can also use Entity Framework

http://sqlite.phxsoftware.com/

不好意思不熟悉语法,但这个概念应该相同。 是这样的:

Sorry not to familiar with the Syntax but the concept should same. Something like :

SQLiteCommand Command = "UPDATE SUBCONTRACTOR SET JobSite = NULL WHERE JobSite = @JobSite";
Command.Parameters.Add(new SQLiteParameter("@JobSite", JobSiteVariable));
command.ExecuteNonQuery();

这篇关于SQLite的问题,逃避某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆