急
我的SQL语句如下
datasource1.DataSet:=query1;
sSql:= 'select * from sxbj where 1=1';
if Edit1.Text <> '' then
sSql := sSql + ' and cj = ' + QuotedStr(Edit1.Text);
if Edit2.Text <> '' then
sSql := sSql + ' and lx = ' + QuotedStr(Edit2.Text);
if Edit3.Text <> '' then
sSql := sSql + ' and xh = ' + QuotedStr(Edit3.Text);
if Edit4.Text <> '' then
sSql := sSql + ' and gb = ' + QuotedStr(Edit4.Text);
if Edit5.Text <> '' then
sSql := sSql + ' and hb = ' + QuotedStr(Edit5.Text);
if Edit6.Text <> '' then
sSql := sSql + ' and sszy = ' + QuotedStr(Edit6.Text);
Query1.sql.Clear;
Query1.SQL.Text := sSql;
query1.ExecSQL;
query1.Active:=true;
运行报datasource1,circular datalinks are not allowed.错,请大家解惑,谢谢
我的SQL语句如下
datasource1.DataSet:=query1;
sSql:= 'select * from sxbj where 1=1';
if Edit1.Text <> '' then
sSql := sSql + ' and cj = ' + QuotedStr(Edit1.Text);
if Edit2.Text <> '' then
sSql := sSql + ' and lx = ' + QuotedStr(Edit2.Text);
if Edit3.Text <> '' then
sSql := sSql + ' and xh = ' + QuotedStr(Edit3.Text);
if Edit4.Text <> '' then
sSql := sSql + ' and gb = ' + QuotedStr(Edit4.Text);
if Edit5.Text <> '' then
sSql := sSql + ' and hb = ' + QuotedStr(Edit5.Text);
if Edit6.Text <> '' then
sSql := sSql + ' and sszy = ' + QuotedStr(Edit6.Text);
Query1.sql.Clear;
Query1.SQL.Text := sSql;
query1.ExecSQL;
query1.Active:=true;
运行报datasource1,circular datalinks are not allowed.错,请大家解惑,谢谢
可能是datasource1或者query1设置错误
而ExecSQL方法还可以用来执行其它常用的SQL语句(如Insert、UPDATE、 DELETE等命令)
请你把你的程序后面的这句
query1.ExecSQL;
改成:
query1.open;以后关于SQL语句的执行可以通用这个格式:
query1.sql := "sql 语言";
try
query1.ExecSQL;
except
query1.open;
end;
sSql:= 'select * from sxbj where 1=1';
Query1.sql.Clear;
Query1.SQL.Text := sSql;
query1.ExecSQL;
//注意这里不能这样使用了,要更新一次
query1.close;
query1.sql.text:='select * from sxbj';
query1.Active:=true;
另外welliam(浪人wwl) 你的這種做法好嗎?如果sql語法錯誤你都找不到錯誤了,不知道sql到底運行了沒有。
try
query1.ExecSQL;
except
query1.open;
end;
sSql:= 'select * from sxbj where 1=1';
if Edit1.Text <> '' then
sSql := sSql + ' and cj = ' + QuotedStr(Edit1.Text);
if Edit2.Text <> '' then
sSql := sSql + ' and lx = ' + QuotedStr(Edit2.Text);
if Edit3.Text <> '' then
sSql := sSql + ' and xh = ' + QuotedStr(Edit3.Text);
if Edit4.Text <> '' then
sSql := sSql + ' and gb = ' + QuotedStr(Edit4.Text);
if Edit5.Text <> '' then
sSql := sSql + ' and hb = ' + QuotedStr(Edit5.Text);
if Edit6.Text <> '' then
sSql := sSql + ' and sszy = ' + QuotedStr(Edit6.Text);
Query1.sql.Clear;
Query1.SQL.Text := sSql;
query1.Active:=true;