请更新SQL UPDATE查询帮助 [英] SQL UPDATE query help please

查看:53
本文介绍了请更新SQL UPDATE查询帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我的SQL查询在我的项目中工作正常,直到它进行了
测试。我发现NvarChar字段我不会接受使用

和'


我的代码和查询在这里有没有人知道如何更改查询

接受''同时保持数据真实。

Dim dbConn2 As SqlConnection = New

SqlConnection(dataQuestions.ConnectionString)


Dim NewQuestion As String = Question.Text


Dim NewAnswer As String = Answer.Text


Dim QuestionID As Integer = CInt(List1.SelectedValue)


Dim CategoryID As Integer = CInt(Category2.SelectedValue)

dbConn2.Open()


Dim strSQL As String =" UPDATE [faq questions] SET问题

=''" &安培; NewQuestion& "'',answer =''" &安培; NewAnswer& "'',categoryID =" &

CategoryID& "其中questionID =" &安培;问题ID


------------------------------------- -------------------------------------------------- -------------------------------------------------- -----


我也试过使用括号如下,但这再次导致

程序崩溃......


Dim strSQL As String =" UPDATE [faq questions] SET问题

=" &安培; NewQuestion& [,answer =" &安培; NewAnswer& "] [,categoryID =" &

CategoryID& "] where questionID =" &安培; QuestionID

任何帮助都会得到很多好处,


Simon

Hi all,

I have a SQL query that worked fine in my project until it came to
testing. I found that the NvarChar fields I have wont accept the use of
an ''

My code and query is here does anyone know how to change the query to
accept an '' whilst keeping the data true.
Dim dbConn2 As SqlConnection = New
SqlConnection(dataQuestions.ConnectionString)

Dim NewQuestion As String = Question.Text

Dim NewAnswer As String = Answer.Text

Dim QuestionID As Integer = CInt(List1.SelectedValue)

Dim CategoryID As Integer = CInt(Category2.SelectedValue)

dbConn2.Open()

Dim strSQL As String = "UPDATE [faq questions] SET question
= ''" & NewQuestion & "'', answer = ''" & NewAnswer & "'', categoryID = " &
CategoryID & " where questionID = " & QuestionID

----------------------------------------------------------------------------------------------------------------------------------------------

I have also tried using brackets as below but this again causes the
program to crash...

Dim strSQL As String = "UPDATE [faq questions] SET question
= " & NewQuestion & "[, answer = " & NewAnswer & "][, categoryID = " &
CategoryID & "] where questionID = " & QuestionID
any help would be much appreceiated,

Simon

推荐答案

Dim strSQL As String =" UPDATE [faq questions] SET问题

=''" &安培; NewQuestion& "'',answer =''" &安培; NewAnswer& "'',categoryID =" &

CategoryID& "其中questionID =" &安培;问题ID


查询是:


UPDATE [faq questions]

SET

question = NewQuestion,

answer = NewAnswer,

categoryID = CategoryID

WHERE

questionID = QuestionID


我假设questionID和categoryID为整数,所以:

Dim strSQL As String =" UPDATE [faq questions] SET" &安培; _

" question =" &安培; "" &安培; NewQuestion& ''

" &安培; _

" answer =" &安培; "" &安培; NewAnswer& ''' &

_

" categoryID =" &安培; CategoryID.ToString

& _

" WHERE questionID =" &

QuestionID.ToString

.....我认为;)


(我喜欢存储的原因之一)程序和参数传递!)



si_owen" < s。**** @ sstaffs.gov.ukwrote in message

news:11 ********************* @ e3g2000cwe .googlegrou ps.com ...
Dim strSQL As String = "UPDATE [faq questions] SET question
= ''" & NewQuestion & "'', answer = ''" & NewAnswer & "'', categoryID = " &
CategoryID & " where questionID = " & QuestionID

The query is:

UPDATE [faq questions]
SET
question = NewQuestion,
answer = NewAnswer,
categoryID = CategoryID
WHERE
questionID = QuestionID

I''m assuming questionID and categoryID as integers, so:

Dim strSQL As String = "UPDATE [faq questions] SET " & _
"question=" & "''" & NewQuestion & "''
" & _
"answer=" & "''" & NewAnswer & "'' " &
_
"categoryID=" & CategoryID.ToString
& _
" WHERE questionID=" &
QuestionID.ToString
..... I think ;)

(one of the reasons I prefer stored procedures and parameter passing!)


si_owen" <s.****@sstaffs.gov.ukwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...

大家好,


我的SQL查询在我的项目中工作正常直到

测试。我发现NvarChar字段我不会接受使用

和'


我的代码和查询在这里有没有人知道如何更改查询

接受''同时保持数据真实。


Dim dbConn2 As SqlConnection = New

SqlConnection(dataQuestions.ConnectionString )


Dim NewQuestion As String = Question.Text


Dim NewAnswer As String = Answer.Text


Dim QuestionID As Integer = CInt(List1.SelectedValue)


Dim CategoryID As Integer = CInt(Category2.SelectedValue)

dbConn2 。打开()


Dim strSQL As String =" UPDATE [faq questions] SET问题

=''" &安培; NewQuestion& "'',answer =''" &安培; NewAnswer& "'',categoryID =" &

CategoryID& "其中questionID =" &安培;问题ID


------------------------------------- -------------------------------------------------- -------------------------------------------------- -----


我也试过使用括号如下,但这再次导致

程序崩溃......


Dim strSQL As String =" UPDATE [faq questions] SET问题

=" &安培; NewQuestion& [,answer =" &安培; NewAnswer& "] [,categoryID =" &

CategoryID& "] where questionID =" &安培; QuestionID


任何帮助都会得到很多好处,


Simon
Hi all,

I have a SQL query that worked fine in my project until it came to
testing. I found that the NvarChar fields I have wont accept the use of
an ''

My code and query is here does anyone know how to change the query to
accept an '' whilst keeping the data true.
Dim dbConn2 As SqlConnection = New
SqlConnection(dataQuestions.ConnectionString)

Dim NewQuestion As String = Question.Text

Dim NewAnswer As String = Answer.Text

Dim QuestionID As Integer = CInt(List1.SelectedValue)

Dim CategoryID As Integer = CInt(Category2.SelectedValue)

dbConn2.Open()

Dim strSQL As String = "UPDATE [faq questions] SET question
= ''" & NewQuestion & "'', answer = ''" & NewAnswer & "'', categoryID = " &
CategoryID & " where questionID = " & QuestionID

----------------------------------------------------------------------------------------------------------------------------------------------

I have also tried using brackets as below but this again causes the
program to crash...

Dim strSQL As String = "UPDATE [faq questions] SET question
= " & NewQuestion & "[, answer = " & NewAnswer & "][, categoryID = " &
CategoryID & "] where questionID = " & QuestionID
any help would be much appreceiated,

Simon



si_owen写道:
si_owen wrote:

我有一个SQL查询,在我的项目中工作正常,直到它来进行
测试。我发现NvarChar字段我不会接受使用

的''
I have a SQL query that worked fine in my project until it came to
testing. I found that the NvarChar fields I have wont accept the use
of an ''



你需要加倍你所有的撇号字符SQL。最简单的方法

是用''''替换''''(这是两个单引号):


\\\

Dim strSQL As String =" UPDATE [faq questions]" _

& SET question =''" &安培;替换(NewQuestion,'''',''''''''& "" _

& ",answer =''" &安培;替换(NewAnswer,'''','''''''& ;; "" _

& ",categoryID =" &安培; CategoryID _

& "其中questionID =" &安培;问题ID

///


这应该可以胜任。


HTH,


-


(O)enone

You need to double up all apostrophe characters in your SQL. The easiest way
is to replace '' characters with '''' (that''s two single quotes):

\\\
Dim strSQL As String = "UPDATE [faq questions] " _
& "SET question = ''" & Replace(NewQuestion, "''", "''''") & "''" _
& ", answer = ''" & Replace(NewAnswer, "''", "''''") & "''" _
& ", categoryID = " & CategoryID _
& " where questionID = " & QuestionID
///

That should do the job.

HTH,

--

(O)enone


多才多艺的作品一种享受


非常感谢。


干杯,


Simon

Thats brilliant works a treat

thanks very much.

Cheers,

Simon


这篇关于请更新SQL UPDATE查询帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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