更新时间:2023-02-05 09:50:49
附上全部单引号中的字符串值:
" INSERT INTO TestTab(Col1,col2,col3,col4)VALUES(''"& str1&"'','' &
dt1&"'',''"& str2&"'',''"& str3&"'')"
如果字符串值包含inturn包含单引号转义它们两个
连续单引号。
HTH。
" ; SM" < sm@discussions.microsoft.com>在消息中写道
新闻:A9 ********************************** @ microsof t.com ...
大家好,
任何人都可以给我通过VB将记录插入SQL服务器的语法
$ b使用变量的$ b代码?
以下语句失败!
sInsertQuery =" INSERT INTO TestTab(Col1,Col2,Col3,Col4)值( & _
str1&","& dt1&","& str2&","& str3&")" ;
其中str1 =" col1"
dt1 = getdate()
str2 =" col2"
str3 =" col3"
谢谢
Hi,
Enclose all string values in single quotes:
"INSERT INTO TestTab (Col1, col2, col3, col4) VALUES (''" & str1 & "'',''" &
dt1 & "'',''" & str2 & "'',''" & str3 & "'')"
If string values contain inturn contain single quote escape them with two
consequtive single quotes.
HTH.
"sm" <sm@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
Hi All,
Can anybody give me the syntax to insert a record into SQL server through VB
code using variables?
The following statement is failing!
sInsertQuery = "INSERT INTO TestTab (Col1, Col2, Col3, Col4) Values(" & _
str1 & "," & dt1 & "," & str2 & "," & str3 & ")"
where str1 = "col1"
dt1 = getdate()
str2 = "col2"
str3 = "col3"
Thanks
谢谢湿婆。
我在字符串值中添加了引号。如下:
sInsertQuery =" INSERT INTO TestTab(Col1,Col2,Col3,Col4)值(& _
"''str1'', dt1,''str2'',''str3'')"
现在我在dt1收到错误
" Shiva"写道:
Thanks Shiva.
I have added quotes to the string values. As follows:
sInsertQuery = "INSERT INTO TestTab (Col1, Col2, Col3, Col4) Values(" & _
"''str1'' , dt1 , ''str2'' , ''str3'')"
Now I get an error at dt1
"Shiva" wrote:
用单引号括起所有字符串值:
" INSERT INTO TestTab(Col1,col2,col3,col4) VALUES(''"& str1&"'',''"&
dt1&"'',''"& str2&"'','' "& str3&"'')"
如果字符串值包含inturn包含单引号,则使用两个
连续单引号将它们转义。
HTH。
sm < sm@discussions.microsoft.com>在消息中写道
新闻:A9 ********************************** @ microsof t.com。 ..大家好,
任何人都可以给我一些语法,通过VB使用变量将代码插入SQL服务器代码吗?
以下声明失败!
sInsertQuery =" INSERT INTO TestTab(Col1,Col2,Col3,Col4)值(& _
str1&","& dt1&"" ,& str2&","& str3&")"
其中str1 =" col1"
dt1 = getdate()
str2 =" col2"
str3 =" col3"
谢谢
Hi,
Enclose all string values in single quotes:
"INSERT INTO TestTab (Col1, col2, col3, col4) VALUES (''" & str1 & "'',''" &
dt1 & "'',''" & str2 & "'',''" & str3 & "'')"
If string values contain inturn contain single quote escape them with two
consequtive single quotes.
HTH.
"sm" <sm@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
Hi All,
Can anybody give me the syntax to insert a record into SQL server through VB
code using variables?
The following statement is failing!
sInsertQuery = "INSERT INTO TestTab (Col1, Col2, Col3, Col4) Values(" & _
str1 & "," & dt1 & "," & str2 & "," & str3 & ")"
where str1 = "col1"
dt1 = getdate()
str2 = "col2"
str3 = "col3"
Thanks
I但是有一个问题,如果值被括在引号中,那么SQL服务器不会将字符串变量
本身视为
值吗?
" Shiva"写道:
I have a question though, won''t SQL server consider the string variable
itself as the
value, if the value is enclosed in quotes?
"Shiva" wrote:
用单引号括起所有字符串值:
" INSERT INTO TestTab(Col1,col2,col3,col4) VALUES(''"& str1&"'',''"&
dt1&"'',''"& str2&"'','' "& str3&"'')"
如果字符串值包含inturn包含单引号,则使用两个
连续单引号将它们转义。
HTH。
sm < sm@discussions.microsoft.com>在消息中写道
新闻:A9 ********************************** @ microsof t.com。 ..大家好,
任何人都可以给我一些语法,通过VB使用变量将代码插入SQL服务器代码吗?
以下声明失败!
sInsertQuery =" INSERT INTO TestTab(Col1,Col2,Col3,Col4)值(& _
str1&","& dt1&"" ,& str2&","& str3&")"
其中str1 =" col1"
dt1 = getdate()
str2 =" col2"
str3 =" col3"
谢谢
Hi,
Enclose all string values in single quotes:
"INSERT INTO TestTab (Col1, col2, col3, col4) VALUES (''" & str1 & "'',''" &
dt1 & "'',''" & str2 & "'',''" & str3 & "'')"
If string values contain inturn contain single quote escape them with two
consequtive single quotes.
HTH.
"sm" <sm@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
Hi All,
Can anybody give me the syntax to insert a record into SQL server through VB
code using variables?
The following statement is failing!
sInsertQuery = "INSERT INTO TestTab (Col1, Col2, Col3, Col4) Values(" & _
str1 & "," & dt1 & "," & str2 & "," & str3 & ")"
where str1 = "col1"
dt1 = getdate()
str2 = "col2"
str3 = "col3"
Thanks