我是用ADO连接EXCEL,我要得到EXCEL表的各个字段名,请问如何实现?
解决方案 »
- parambynmae怎么使用
- delphi中什么控件支持http代理连接服务器?
- 怎样得到打印机当前纸装名称(如A4)?
- 在程序如何设定系统的日期格式为:yyyy-MM-DD HH:MM?
- 程序运行了一两个小时后弹出一对话框“List Index Out Of bound(2)”,请问是什么问题?
- 如何调用“数据链接属性”对话框?
- 这回有人回答了吧???
- 如何判断一个目录是否存在,要用到哪个函数。
- 用ExpressQuantumGrid v4的程序如何转换为ExpressQuantumGrid v6
- 如何通过ms proxy server来编程实现流量统计?
- 数据库问题
- locate在adoquery中怎么用?
uses ADOConED;//打开ADO配置对话框,尝试连接用户指定的库
procedure TServerMainForm.btGetDSClick(Sender: TObject);
begin
try
ADOConnection1.Close;
EditConnectionString(ADOConnection1);
ADOConnection1.Open;
GetAllTables; //**获得数据库中的表**//
Application.MessageBox('连接成功!!!','成功信息',MB_DEFBUTTON1);
except on E:Exception do
ADOConnection1.Close;
Application.MessageBox('连接失败,请检查设置!','错误信息',MB_DEFBUTTON1);
end;
end;//获得数据库中的表及字段名
procedure TServerMainForm.GetAllTables;
var
tbList : TStringList;
iTableCount, iFieldCount : Integer;
sTableName, sFieldName : string;
TreeNode : TTreeNode;
begin
tbList:=TStringList.Create;
try
ADOConnection1.GetTableNames(tbList);
for icount:=0 to tbList.Count-1 do
begin
sTableName:=tbList.Strings[icount];
TreeNode:=TreeView1.Items.Add(nil,sTableName); if adoDataSet.Active then adoDataSet.Close;
adoDataSet.CommandText := Format('Select * from %s',[sTableName]);
adoDataSet.Open;
//获得字段名
for iFieldCount := 0 to adoDataSet.FieldCount-1 do
begin
sFieldName := adoDataSet.Fields[iCount].FieldName;
TreeView1.Items.Add(TreeNode,sFieldName);
end;
adoDataSet.Close;
finally
tbList.Free;
end;
end;adoDataSet类型为ADODataSet。只要你的Excel表结构正确,就可以获得其中的表名及所有的字段名。上面的代码对所有使用ADO驱动的如Excel,Access,SqlServer,Oracle等同样有效。敲了这么半天,午睡也耽搁了:)
100分拿来!!!!