关于在SQL里查询中文数据的问题

Scandinavians 2008-08-05 09:01:48
请问大侠们,在delphi 7里用SQL语句查询 中文值字段的时候,会提示列名无效,有什么好的解决办法么!?
...全文
139 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
may_05 2008-08-06
  • 打赏
  • 举报
回复
5楼正解.
或者你用:
with AdoQuery1 do
begin
close;
SQL.Clear;
SQL.Add('Select * from Buslines where Drivername=:DriverName');
Parameters.ParamByName('DriverName').Value:=Trim(Edit1.text);
Open;
end;
阿三 2008-08-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 flyapy 的回复:]
中文字符的两边要引号?双引号单引号啊 !?
[/Quote]
试试5楼的就知道了,都是单引号
wjbwjb 2008-08-05
  • 打赏
  • 举报
回复
with AdoQuery1 do
begin
close;
SQL.Clear;
SQL.Add('Select * from Buslines where Drivername='''+Trim(Edit1.text)+'''');
Open;
end;
radarhp 2008-08-05
  • 打赏
  • 举报
回复
灭有这种说法滴说,数据库不用中文就灭有办法用这个数据库了
shuihan20e 2008-08-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 flyapy 的回复:]
with AdoQuery1 do
begin
close;
SQL.Clear;
SQL.Add('Select * from Buslines where Drivername='+Trim(Edit1.text));
Open;
end;

在Edit1中输入中文驾驶员名字的时候查询就会报错列名无效!
[/Quote]

代码有错误,你可以这样

with AdoQuery1 do
begin
close;
SQL.Clear;
SQL.Add('Select * from Buslines where Drivername='+Trim(Edit1.text));
ShowMessage(SQL.Text);//显示一下,看看是否正确
Open;
end;
youcunzai 2008-08-05
  • 打赏
  • 举报
回复
你拿我的代码去试试不就知道了啊
Scandinavians 2008-08-05
  • 打赏
  • 举报
回复
中文字符的两边要引号?双引号单引号啊 !?
youcunzai 2008-08-05
  • 打赏
  • 举报
回复
中文字段 是允许的!我很多都是中文的;

你的代码有错误!
应该

with AdoQuery1 do
begin
close;
SQL.Clear;
SQL.Add('Select * from Buslines where Drivername='''+Trim(Edit1.text)+''''); //字符需要引号
Open;
end;
Scandinavians 2008-08-05
  • 打赏
  • 举报
回复
with AdoQuery1 do
begin
close;
SQL.Clear;
SQL.Add('Select * from Buslines where Drivername='+Trim(Edit1.text));
Open;
end;

在Edit1中输入中文驾驶员名字的时候查询就会报错列名无效!
kaikai_kk 2008-08-05
  • 打赏
  • 举报
回复
别用
arashi50000 2008-08-05
  • 打赏
  • 举报
回复
没用过中文作字段

不过好像有同事用过没听说会报错啊,把你解的列出来看一下
老之 2008-08-05
  • 打赏
  • 举报
回复
别用中文作为字段名

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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