关于adodb的 查询

shenfuhua 2002-03-08 03:00:50
我在处理数据库的数据时,想用汉字查询如a.open "select * form success where name="程序",g_conn,,adcmdtex"
它老是出错。是不是ADODB中的SQL不支持汉字查询
shenfuhua_129@163.net
...全文
51 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
worldtomev 2002-03-13
  • 打赏
  • 举报
回复
不然用我的mdb和project试试(email?)
worldtomev 2002-03-13
  • 打赏
  • 举报
回复
我这完全没问题!(唯一的上面的代码忘删了'Set conn = opdb()' )
估计你的odbc连接不对!控制面板-管理工具-odbc..
seafarer777 2002-03-08
  • 打赏
  • 举报
回复
如果是字符串变量:
"SELECT * FROM 表名 where 字段='" & text1 & "'"
如果是字符串常量:
"SELECT * FROM 表名 where 字段='中文'"

tony_jian 2002-03-08
  • 打赏
  • 举报
回复
rst.Find "用户名='" & textuser.Text & "'"
shenfuhua 2002-03-08
  • 打赏
  • 举报
回复
Set rs = conn.Execute("select * from student where xm='水粉画'")
他执行的错误是期待的参数是1
Too few parameters. expected 1
worldtomev 2002-03-08
  • 打赏
  • 举报
回复
不知道你的代码和错误信息怎么判断!
shenfuhua 2002-03-08
  • 打赏
  • 举报
回复
还不行
SenseKey 2002-03-08
  • 打赏
  • 举报
回复
怎么回事显示不对另写一遍了 a.open "select * from success where name=' " 程序 " ' "
worldtomev 2002-03-08
  • 打赏
  • 举报
回复
Dim conn
Set conn = CreateObject("adodb.connection")
conn.Open "dsn=sms"
Dim rs
Set conn = opdb()

Set rs = CreateObject("adodb.recordset")
Set rs = conn.Execute("select * from student where xm='水粉画'")
SenseKey 2002-03-08
  • 打赏
  • 举报
回复

看这个 a.open "select * from success where name='" 程序 "'"
worldtomev 2002-03-08
  • 打赏
  • 举报
回复
DSN....Really? (OLEDB)
Perhaps DNS
shenfuhua 2002-03-08
  • 打赏
  • 举报
回复
我现在还是有错,help help
worldtomev 2002-03-08
  • 打赏
  • 举报
回复
a.open "select * form success where name='程序'",g_conn,,adcmdtex
shenfuhua 2002-03-08
  • 打赏
  • 举报
回复
模块中有Public g_conn As ADODB.Connection
from1中的代码
Public Sub Opendatabase()
Set g_conn = New ADODB.Connection
g_conn.ConnectionString = "DSN=sms"
g_conn.Open
If g_conn.State <> adStateOpen Then
MsgBox "数据库打开失败", vbOKOnly + vbCritical + conAppName
Unload frmMain
End If
End Sub

Private Sub Form_Load()
Opendatabase
Dim a As ADODB.Recordset
Set a = New ADODB.Recordset
a.Open "select * from student where xm='水粉画'", g_conn, adOpenStatic, adLockOptimistic, adCmdText
End Sub
出现以错误Too few parameters. expected 1
bamboo_leo 2002-03-08
  • 打赏
  • 举报
回复
ADODB中的SQL是完全支持汉字查询的,从你贴出的贴子来看,是SQL语句的问题。在VB的SQL语句中如果条件为字符串应该用单引号,不能用双引号。如果非要双引号,应该用Chr(34)来代替。
例如:
sSQL="Select a from a='条件'"

sSQL="select a from a=" & chr(34) & "条件" & chr(34)
cubel 2002-03-08
  • 打赏
  • 举报
回复
汉字完全可以的,还可以用like
yanz 2002-03-08
  • 打赏
  • 举报
回复
语句改写如下:

a.open "select * form success where name='程序'",g_conn,,adcmdtex"

若汉字在变量中,如下:
a.open "select * form success where name='" & var & "'",g_conn,,adcmdtex"
forever_chang 2002-03-08
  • 打赏
  • 举报
回复
汉字完全可以作为查询条件
pengnick 2002-03-08
  • 打赏
  • 举报
回复
name="程序"中的双引号应为单引号,正确写法如下:
a.open "select * form success where name='程序'",g_conn,,adcmdtex
forever_chang 2002-03-08
  • 打赏
  • 举报
回复
将汉字两边的双引号改为单引号

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧