N
ning_ning
Unregistered / Unconfirmed
GUEST, unregistred user!
请看这个例程,关键点如下:
Recordset:=ADOServer.ConnectionObject.OpenSchema(adSchemaColumns,
VarArrayOf([Null, Null, list_TableName.Items[nLoop]]),EmptyParam);
RecordSet.MoveFirst;
RecordSet.Fields['ORDINAL_POSITION'].Value,
RecordSet.Fields['COLUMN_NAME'] .Value,
GetDataType(RecordSet.Fields['DATA_TYPE'] .Value),
RecordSet.Fields['CHARACTER_MAXIMUM_LENGTH'].Value,
RecordSet.Fields['NUMERIC_PRECISION'] .Value,
RecordSet.Fields['NUMERIC_SCALE'] .Value,
RecordSet.Fields['IS_NULLABLE'] .Value]);
{ 得到字段表 }
procedure TwinDBTools.list_TableNameClick(Sender: TObject);
var
nLoop:Integer;
RecordSet:_RecordSet;
begin
sTableName:='';
txt_TableName.Enabled:=false;
rb_Data.Enabled:=true;
nLoop:=0;
while nLoop<list_TableName.Items.Count-1 do begin
if list_TableName.Selected[nLoop]=true then break;
nLoop:=nLoop +1;
end;
if nLoop<list_TableName.Items.Count then begin
sTableName:=list_TableName.Items[nLoop];
Recordset:=ADOServer.ConnectionObject.OpenSchema(adSchemaColumns,
VarArrayOf([Null, Null, list_TableName.Items[nLoop]]),EmptyParam);
RecordSet.MoveFirst;
dbField.Close;
dbField.CreateDataSet;
while not RecordSet.EOF do begin
dbField.AppendRecord([
RecordSet.Fields['ORDINAL_POSITION'].Value,
RecordSet.Fields['COLUMN_NAME'] .Value,
GetDataType(RecordSet.Fields['DATA_TYPE'] .Value),
RecordSet.Fields['CHARACTER_MAXIMUM_LENGTH'].Value,
RecordSet.Fields['NUMERIC_PRECISION'] .Value,
RecordSet.Fields['NUMERIC_SCALE'] .Value,
RecordSet.Fields['IS_NULLABLE'] .Value]);
RecordSet.MoveNext;
end;
dbField.Sort:='ColumnCode ASC';
txt_TableName.Text:=sTableName;
dbDataSet.Close;
dbDataSet.CommandText:='SELECT * FROM '+sTableName;
try
dbDataSet.Open;
except
on e:exception do begin
pbc_ShowRunning('');
sql_ShowWarning('读取‘'+sTableName+'’数据表数据失败!',e.Message);
exit;
end;
end;
end;
end;
Recordset:=ADOServer.ConnectionObject.OpenSchema(adSchemaColumns,
VarArrayOf([Null, Null, list_TableName.Items[nLoop]]),EmptyParam);
RecordSet.MoveFirst;
RecordSet.Fields['ORDINAL_POSITION'].Value,
RecordSet.Fields['COLUMN_NAME'] .Value,
GetDataType(RecordSet.Fields['DATA_TYPE'] .Value),
RecordSet.Fields['CHARACTER_MAXIMUM_LENGTH'].Value,
RecordSet.Fields['NUMERIC_PRECISION'] .Value,
RecordSet.Fields['NUMERIC_SCALE'] .Value,
RecordSet.Fields['IS_NULLABLE'] .Value]);
{ 得到字段表 }
procedure TwinDBTools.list_TableNameClick(Sender: TObject);
var
nLoop:Integer;
RecordSet:_RecordSet;
begin
sTableName:='';
txt_TableName.Enabled:=false;
rb_Data.Enabled:=true;
nLoop:=0;
while nLoop<list_TableName.Items.Count-1 do begin
if list_TableName.Selected[nLoop]=true then break;
nLoop:=nLoop +1;
end;
if nLoop<list_TableName.Items.Count then begin
sTableName:=list_TableName.Items[nLoop];
Recordset:=ADOServer.ConnectionObject.OpenSchema(adSchemaColumns,
VarArrayOf([Null, Null, list_TableName.Items[nLoop]]),EmptyParam);
RecordSet.MoveFirst;
dbField.Close;
dbField.CreateDataSet;
while not RecordSet.EOF do begin
dbField.AppendRecord([
RecordSet.Fields['ORDINAL_POSITION'].Value,
RecordSet.Fields['COLUMN_NAME'] .Value,
GetDataType(RecordSet.Fields['DATA_TYPE'] .Value),
RecordSet.Fields['CHARACTER_MAXIMUM_LENGTH'].Value,
RecordSet.Fields['NUMERIC_PRECISION'] .Value,
RecordSet.Fields['NUMERIC_SCALE'] .Value,
RecordSet.Fields['IS_NULLABLE'] .Value]);
RecordSet.MoveNext;
end;
dbField.Sort:='ColumnCode ASC';
txt_TableName.Text:=sTableName;
dbDataSet.Close;
dbDataSet.CommandText:='SELECT * FROM '+sTableName;
try
dbDataSet.Open;
except
on e:exception do begin
pbc_ShowRunning('');
sql_ShowWarning('读取‘'+sTableName+'’数据表数据失败!',e.Message);
exit;
end;
end;
end;
end;