listbox的用法(查询、oracle)!!! (400分)!!! (200分)

to:hongxing_dl 提示为‘无效列名’。拜托!
 
跟踪过没?
是这下面的语句的错误吗:
procedure TzhcxFrm.okClick(Sender: TObject);
var
i:integer;
begin
with dm.Query2 do
begin
sql.Text:= 'select * from zhcx where ';
for i:=0 to listbox1.Items.Count-1 do
sql.text:=sql.text+listbox1.items;
open;
end;
end;
还是建立视图时出了错?
 
to:hongxing_dl
是这下面的语句的错误
procedure TzhcxFrm.okClick(Sender: TObject);
var
i:integer;
begin
with dm.Query2 do
begin
sql.Text:= 'select * from zhcx where ';
for i:=0 to listbox1.Items.Count-1 do
sql.text:=sql.text+listbox1.items;
open;
end;
end;
建立视图时没错。
另外一个问题中decode(nvl(n01,0),0,null,1)变成decode(n01,0,0,null,0,1)通过了。那个贴先结了。谢谢你。
 
decode(nvl(n01,0),0,null,1)我这边都通过的啊,你用的Oracle哪个版本哦,啊……都解决了,不说这个问题了。
上面那个问题可能就要追溯到你的条件上去了,肯定是条件上出问题了。
把你那些'''''''''+zcb.Text+''''''''',删去一些,改成
'''+zcb.text+''' 其他的一样
或者把最终生成的SQL贴上来看看。
 
还有这么懒的人,不过也好,让其他人动动手喽,可以让别人锻炼一下,还可以那分,也还OK吧
 
这有一段代码,你看看吧:
procedure TfrmMain.btnFindClick(Sender: TObject);
var
Text: String;
i: Word;
begin
if cmbFs.ItemIndex < 0 then Exit;
if rbBookname.Checked then begin
if edtWhat.Text = '' then Exit;
Text := 'select * from booklist where sm like ''';
case cmbFs.ItemIndex of
0: Text := Text + edtWhat.Text + '''';
1: Text := Text + edtWhat.Text + '%''';
3: Text := Text + '%' + edtWhat.Text + '''';
2: Text := Text + '%' + edtWhat.Text + '%''';
end;
end else if rbCbs.Checked then begin
if edtWhat.Text = '' then Exit;
Text := 'select * from booklist where cbs like ''';
case cmbFs.ItemIndex of
0: Text := Text + edtWhat.Text + '''';
1: Text := Text + edtWhat.Text + '%''';
3: Text := Text + '%' + edtWhat.Text + '''';
2: Text := Text + '%' + edtWhat.Text + '%''';
end;
end else if rbDj.Checked then begin
try
StrToFloat(edtWhat.Text);
except
Exit;
end;
Text := 'select * from booklist where dj ';
case cmbFs.ItemIndex of
0: Text := Text + '= ' + edtWhat.Text;
1: Text := Text + '<= ' + edtWhat.Text;
2: Text := Text + '>= ' + edtWhat.Text;
end;
end else if rbRksj.Checked then begin
Text := 'select * from booklist where rksj ';
case cmbFs.ItemIndex of
0: Text := Text + '= ''' + FormatDateTime('yyyy-mm-dd', dtpWhat.Date) + '''';
1: Text := Text + '<= ''' + FormatDateTime('yyyy-mm-dd', dtpWhat.Date) + '''';
2: Text := Text + '>= ''' + FormatDateTime('yyyy-mm-dd', dtpWhat.Date) + '''';
end;
end else if rbZz.Checked then begin
if edtWhat.Text = '' then Exit;
Text := 'select * from booklist where zz like ''';
case cmbFs.ItemIndex of
0: Text := Text + edtWhat.Text + '''';
1: Text := Text + edtWhat.Text + '%''';
3: Text := Text + '%' + edtWhat.Text + '''';
2: Text := Text + '%' + edtWhat.Text + '%''';
end;
end else if rbCbrq.Checked then begin
Text := 'select * from booklist where cbrq ';
case cmbFs.ItemIndex of
0: Text := Text + '= ''' + FormatDateTime('yyyy-mm-dd', dtpWhat.Date) + '''';
1: Text := Text + '<= ''' + FormatDateTime('yyyy-mm-dd', dtpWhat.Date) + '''';
2: Text := Text + '>= ''' + FormatDateTime('yyyy-mm-dd', dtpWhat.Date) + '''';
end;
end else if rbSl.Checked then begin
try
StrToFloat(edtWhat.Text);
except
Exit;
end;
Text := 'select * from booklist where sl ';
case cmbFs.ItemIndex of
0: Text := Text + '= ' + edtWhat.Text;
1: Text := Text + '<= ' + edtWhat.Text;
2: Text := Text + '>= ' + edtWhat.Text;
end;
end;
Text := Text + ' order by id';
btnFind.Enabled := False;
dmData.cdsBook.DisableControls;
lvFind.Items.BeginUpdate;
lvFind.Items.Clear;
with dmData.cdsBook do begin
Active := False;
DataSet.CommandText := Text;
DataSet.Prepared := True;
Active := True;
i := 0;
First;
while not eof do begin
lvFind.Items.Add;
lvFind.Items.ImageIndex := 1;
lvFind.Items.Caption := FieldByName('sm').AsString;
lvFind.Items.SubItems.Add(FieldByName('sysh').AsString);
lvFind.Items.SubItems.Add(FieldByName('cbs').AsString);
lvFind.Items.SubItems.Add(FieldByName('dj').AsString);
lvFind.Items.SubItems.Add(FieldByName('rksj').AsString);
lvFind.Items.SubItems.Add(FieldByName('lbmc').AsString);
lvFind.Items.SubItems.Add(FieldByName('zz').AsString);
lvFind.Items.SubItems.Add(FieldByName('cbrq').AsString);
lvFind.Items.SubItems.Add(FieldByName('sl').AsString);
Inc(i);
Next;
end;
end;
dmData.cdsBook.EnableControls;
lvFind.Items.EndUpdate;
btnFind.Enabled := True;
end;
 
procedure TForm1.Button1Click(Sender: TObject); //反复设置条件
begin
if ListBox1.Items.Text<>'' then //如果已存在条件
begin
if MessageBox(Handle,'有两个以上条件时,要设定条件间的关系,点 击'+#13+ '"是"按钮将设置为“与”关系,点击"否"按钮将'+#13+设置为“或”关系,请根据具体情况选择。','提问',MB_YESNO+MB_ICONQUESTION)=IDYES then
ListBox1.Items.Append('and')
else ListBox1.Items.Append('or');
end;
if (Table1.FieldByName(ComboBox1.Text)=ftString then
ListBox1.Items.Append(ComboBox1.Text+ ComboBox2.Text+ #39+ComboBox3.Text+#39) //如字段类型是字符型,加单引号
else ListBox1.Items.Append(ComboBox1.Text+ ComboBox2.Text+ ComboBox3.Text);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Query1.Sql.Text:='Select * from xxx where ' +ListBox1.Items.Text;
Query1.Active:=true;
end;
 
多谢各位的帮忙!
 
多人接受答案了。
 
顶部