我用第三方控件cxDBComboBox,用ado连接Access数据库,当点击cxDBComboBox时,下拉列表中的Item清除,然后重新从一个数据表中选择该列的值添加到cxDBComboBox的下拉列表中,用代码怎么写呀?我是初学者,折腾两天了快要放弃了,才到此胜地求救!大师们可否提供完全的代码,先谢了!
顺便问一下,ado连接数据库的信息放在一个文件中,无论该程序移植到那都不用该connectionstring 就能运行,这个文件怎么写呀?
顺便问一下,ado连接数据库的信息放在一个文件中,无论该程序移植到那都不用该connectionstring 就能运行,这个文件怎么写呀?
解决方案 »
- 新手 怎么解决cannot find implementation of method ()
- 请问如何设置工具栏图标的大小?
- 客户端无法连接中间层
- 用data module 做二,三层问题???
- 简单问题,各位请帮忙,在delphi中如何写模糊查询语句?
- 用SQL将表字段改名问题:
- sqrt函数操作数需要extend变量,可我用的变量是integer,两者如何转换??谢谢!
- 如何取得WINDOWS系统内在的所有图标,是否要用到系统图象别表,我现在只能有SHgetfileinfo函数得到系统图象列表的句柄
- delphi6比delphi5多些什么东西?我正在学5呢,6又出来了。
- 注册码问题,如何用已知的用户名字使用反运算得到数字?请给出原代码,异或运算就可以了!谢谢!
- 怎样读出listview中鼠标选中的item中的各个column的值。
- 组合查询的问题?高手帮忙
begin
with datamodule1.TDF_Manu do
begin
first;
while not eof do
begin
DBComboBox7.Items.Add(fieldbyname('manu').AsString);
next;
end;
end;
ini 文件connect.ini
[connect]
Server=Server01
DB=YLJZ
User=YLJZ
Ps=YLJZ连接
var
ConnectIni:TIniFile;
FileName:String;
servername,DB,User,Ps:string;
begin
FileName:='c:\connect.ini';
ConnectIni:=TIniFile.Create(FileName);
ServerName:=ConnectIni.ReadString('connect','server','null');
DB:=ConnectIni.ReadString('connect','DB','null');
User:=ConnectIni.ReadString('connect','User','null');
Ps:=ConnectIni.ReadString('connect','Ps','null');
AdoConnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='+ps+';Persist Security Info=True;';
AdoConnection1.ConnectionString:=AdoConnection1.ConnectionString+'User ID='+User+';Initial Catalog='+DB+';Data Source='+ServerName+'';
try
AdoConnection1.Connected:=True;
except
showmessage('请检查数据库连接');
end;
在cxDBComboBox 的onEnter时间里加入如下代码
with adoquery1 do
begin
close;
sql.text := 'select Item from aTable';
open;
cxDBComboBox.items.clear;
while not eof do
begin
cxDBComboBox.items.add(fields[0].asstring);
next;
end;
close;
end;关于第二个问题你可以将这个字符串存到一个ini文件中,每次数据模块创建时从改文件中读取该串,然后将adoconnection的connectionString设成这个字符串即可
怎么编译出错提示:[Error] Unit2.pas(139): Undeclared identifier: 'items'
--------------------------
procedure TForm1.cxDBComboBox1DropDown(Sender: TObject);
begin
with cxDBComboBox1.Items do
try
BeginUpdate;
Clear;
//添加代码部分就用楼上的吧
finally
EndUpdate;
end;
end;
这是怎么回事呀?
begin
combobox1.Clear;
adoquery1.First;
while not adoquery1.Eof do
begin
combobox1.Items.Add(adoquery1.FieldByName('Id').AsString);
adoquery1.Next;
end;
end;
begin
close;
sql.clear;
sql.add(' select * from table_name');
try
open;
cxDBComboBox.Properties.Items.Clear;
while not eof do
begin
cxDBComboBox.Properties.Items.add(Fieldbyname('字段名').value);
next;
end;
except
end;
end;
begin
close;
sql.Clear;
sql.text := 'Insert Into tbCarriage (CarriageNo,Memo) Values(:CarriageNo,:Memo)';
Parameters.ParamByName('CarriageNo').Value := ComboBox1.Text;
Parameters.ParamByName('Memo').Value := Memo1.Text;
ExecSQL;
close;
end;
怎么运行时老是出错,要是把改成如下就不会出错,而求数据库(access)中Memo字段允许为空
with ADOQuery1 do
begin
close;
sql.Clear;
sql.text := 'Insert Into tbCarriage (CarriageNo) Values(:CarriageNo)';
Parameters.ParamByName('CarriageNo').Value := ComboBox1.Text;
Parameters.ParamByName('Memo').Value := Memo1.Text;
ExecSQL;
close;
end;
我用的是自带的Memo控件,为什么用Memo就会出错说是Inser Into语句语法错误,去了他就没错,这是怎么回事呀?
begin
close;
sql.Clear;
sql.text := 'Insert Into tbCarriage (CarriageNo,Memo) Values(:CarriageNo,:Memo)';
Parameters.ParamByName('CarriageNo').Value := ComboBox1.Text;
Parameters.ParamByName('Memo').Value := Memo1.Text;
ExecSQL;
close;
end;
怎么运行时老是出错,要是把改成如下就不会出错,而求数据库(access)中Memo字段允许为空
with ADOQuery1 do
begin
close;
sql.Clear;
sql.text := 'Insert Into tbCarriage (CarriageNo) Values(:CarriageNo)';
Parameters.ParamByName('CarriageNo').Value := ComboBox1.Text;
ExecSQL;
close;
end;
我用的是自带的Memo控件,为什么用Memo就会出错说是Inser Into语句语法错误,去了他就没错,这是怎么回事呀?
数据库里面的字段是什么类型??
数据库是文本的
begin
close;
sql.Clear;
sql.text := 'Insert Into tbCarriage (CarriageNo,Memo) Values(:CarriageNo,:Memo)';
Parameters.ParamByName('CarriageNo').Value := ComboBox1.Text;
Parameters.ParamByName('Memo').Value := Memo1.Text;
ExecSQL;
close;
end;
怎么运行时老是出错,要是把改成如下就不会出错,而求数据库(access)中Memo字段允许为空
with ADOQuery1 do
begin
close;
sql.Clear;
sql.text := 'Insert Into tbCarriage (CarriageNo) Values(:CarriageNo)';
Parameters.ParamByName('CarriageNo').Value := ComboBox1.Text;
ExecSQL;
close;
end;
我用的是自带的Memo控件,为什么用Memo就会出错说是Inser Into语句语法错误,去了他就没错,这是怎么回事呀?
combobox的text类型和memo的text类型
数据库是文本的