自己写的一个数据库小东西 http://download.csdn.net/source/1428768没什么大用查看表的时候方便一点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);var Filename: string; MyIniFile: TInifile;begin Filename := ExtractFilePath(Paramstr(0)) + 'program.ini'; MyIniFile := TInifile.Create(Filename); try EdtServer.Text := MyIniFile.ReadString('ServerAddress', 'ServerName', '.'); Edit1.Text := MyIniFile.ReadString('ServerAddress', 'count', '100'); Edit2.Text := MyIniFile.ReadString('ServerAddress', 'row', '1'); EdtPsd.Text := MyIniFile.ReadString('ServerAddress', 'psd', 'mymsserver'); edtName.Text := MyIniFile.ReadString('ServerAddress', 'name', 'wlms'); finally FreeAndNil(MyIniFile); end;end;procedure TForm1.btLogClick(Sender: TObject);begin if (EdtServer.Text = '') then begin ShowMessage('输入服务器地址!'); exit; end; ADOQCon.Connected := False; ADOQCon.ConnectionString := ''; try ADOQCon.ConnectionString := 'Provider=SQLOLEDB.1;Password=' + EdtPsd.Text + ';Persist Security Info=True;User ID=' + edtName.Text + ';Initial Catalog= master;Data Source=' + EdtServer.Text + ';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=' + EdtServer.Text + ';Use Encryption for Data=False;Tag with column collation when possible=False'; ADOQCon.Connected := True; ADOQCon.Connected := true; ADOQServerList.Connection := ADOQCon; ADOQServerList.Open; ADOQServerList.First; ComboBox1.Items.Clear; while not ADOQServerList.Eof do begin ComboBox1.Items.Add(ADOQServerList.FieldValues['name']); ADOQServerList.Next; end; ShowMessage('连接成功!'); ADOQCon.Connected := False;// ADOQTable.Connection := ADOQCon;// s_cmd := 'select o.name,i.rows ID' + #13#10 +// 'from sysobjects o,sysindexes i' + #13#10 +// 'where o.id=i.id and o.Xtype=''U'' and i.indid<2' + #13#10;// s_cmd := s_cmd + ' and i.rows >='+inttostr(StrToIntDef(edit2.Text,-1));// ADOQTable.SQL.Text := s_cmd + ' order by o.name';// ADOQTable.Open; except ShowMessage('连接不正常!'); end;end;procedure TForm1.btExitClick(Sender: TObject);begin ADOQCon.Connected := false; Close;end;procedure TForm1.cxGrid2DBTableView1CellClick( Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);var BandColumn: TcxGridDBColumn; i: Integer;begin try for i := cxGrid1DBTableView1.ColumnCount - 1 downto 0 do begin cxGrid1DBTableView1.Columns[i].Destroy; end; ADOQList.Connection := ADOQCon; ADOQFieldList.Connection := ADOQCon; ADOQList.SQL.Text := 'SELECT TOP ' + edit1.text + ' * FROM [' + ADOQTable.FieldValues['name'] + ']'; ADOQList.Open; for I := 0 to ADOQList.FieldCount - 1 do begin BandColumn := cxGrid1DBTableView1.CreateColumn; BandColumn.Caption := ADOQList.Fields.Fields[I].FieldName; BandColumn.DataBinding.FieldName := ADOQList.Fields.Fields[I].FieldName; BandColumn.Width := 100; end; ADOQFieldList.SQL.Text := 'declare @TableName varchar(255) , @script_type char(1)' + #13#10 + '----------------------------------------' + #13#10 + '-- 参数' + #13#10 + '----------------------------------------' + #13#10 + 'set @TableName = ''' + ADOQTable.FieldValues['name'] + '''' + #13#10 + '----------------------------------------' + #13#10 + 'declare @str varchar(8000) ' + #13#10 + 'set @str = '''' ' + #13#10 + 'select cols.colorder as 序号,' + #13#10 + '''['' + cols.name + ''] ''as 列名,' + #13#10 + 'type.name+ ( case when cols.xtype in (165,167,173,175,231,239)' + #13#10 + 'then ''(''+ convert(varchar(10) , cols.prec) + '')''' + #13#10 + 'when cols.xtype in (106,108)' + #13#10 + 'then ''(''+ convert(varchar(10) , cols.prec)+'' , '' + convert(varchar(10) ,cols.scale)+ '') ''' + #13#10 + 'else '''' end ) as 列类型,' + #13#10 + 'case isnull(cols.collation,''a'') when ''a'' then '''' else ''COLLATE ''+cols.collation end 排序,' + #13#10 + 'case cols.isnullable when 1 then ''NULL'' ELSE ''NOT NULL'' END as 为空,' + #13#10 + 'isnull(com.text,'''') 默认值,' + #13#10 + 'isnull (d.[value],'''' ) as 字段说明,' + #13#10 + 'case when COLUMNPROPERTY (cols.id,cols.name,''isidentity'') = 1 then ''√'' else '''' end 标识,' + #13#10 + '( case when (' + #13#10 + 'select count(*) from sysobjects' + #13#10 + 'where name in (' + #13#10 + 'select name from sysindexes where (id = cols.id ) and ( indid in' + #13#10 + '(select indid from sysindexkeys where' + #13#10 + '( id = cols.id ) and ( colid in (' + #13#10 + 'select colid from syscolumns' + #13#10 + 'where ( id = cols.id ) and ( name = cols.name ))))))' + #13#10 + 'and ( xtype =''PK'')) > 0 then ''√'' else '''' end ) 主键' + #13#10 + 'from syscolumns cols' + #13#10 + 'left join systypes type' + #13#10 + 'on cols.xtype = type.xtype and cols.xtype = type.xusertype left join syscomments com on cols.cdefault=com.id left join sysproperties d on cols.id=d.id and cols.colid=d.smallid' + #13#10 + 'where cols.id = (select id from sysobjects where name = @TableName) '; Memo1.Text:=ADOQFieldList.SQL.Text; ADOQFieldList.Open; except ShowMessage('查询出错!'); end;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);var FileName: string; MyIniFile: TInifile;begin Filename := ExtractFilePath(Paramstr(0)) + 'program.ini'; MyIniFile := TInifile.Create(Filename); try MyIniFile.writestring('ServerAddress', 'ServerName', EdtServer.Text); MyIniFile.writestring('ServerAddress', 'count', Edit1.Text); MyIniFile.writestring('ServerAddress', 'row', Edit2.Text); MyIniFile.writestring('ServerAddress', 'psd', EdtPsd.Text); MyIniFile.writestring('ServerAddress', 'name', edtName.Text); finally FreeAndNil(MyIniFile); end;end;procedure TForm1.ComboBox1Change(Sender: TObject);var s_cmd: string;begin if ComboBox1.Text = '' then exit; try ADOQCon.Connected := false; ADOQCon.ConnectionString := ''; ADOQCon.ConnectionString := 'Provider=SQLOLEDB.1;Password=' + EdtPsd.Text + ';Persist Security Info=True;User ID=' + edtName.Text + ';Initial Catalog= ' + ComboBox1.Text + ';Data Source=' + EdtServer.Text + ';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=' + EdtServer.Text + ';Use Encryption for Data=False;Tag with column collation when possible=False'; ADOQCon.Connected := True; ADOQCon.Connected := True; ADOQTable.Connection := ADOQCon; s_cmd := 'select o.name,i.rows ID' + #13#10 + 'from sysobjects o,sysindexes i' + #13#10 + 'where o.id=i.id and o.Xtype=''U'' and i.indid<2' + #13#10; s_cmd := s_cmd + ' and i.rows >=' + inttostr(StrToIntDef(edit2.Text, -1)); ADOQTable.SQL.Text := s_cmd + ' order by o.name'; ADOQTable.Open; except ShowMessage('连接不正常!'); end;end;end. 发源码多好呀,我下了后是个exe?怪。 楼主现在Delphi好象没什么人在用! 行转列。Value值为String类型,如果合并 请教高手一个存储过程的问题 请高手大哥帮忙! 关于数据库的安装问题!请大家帮我解决一下! 如何将一个变量作为一个列插入select的结果中??具体问题内详~~ 表分区出错了,大家看一下 SQL请教怎样在值为 null 的后面追加字符串 MSDE代理使用问题?发生错误-5(拒绝访问.),此时正在SQLServerAgent服务上执行该服务操作. 怎么用sql邮件发信? 请教sqlserver配置 使用【A】表与【B】表的【A.体积】合计与【B.产品编码】计数的最大值作为条件得到【结果】表。 SQL server 里截字段使用到的函数
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
Filename: string;
MyIniFile: TInifile;
begin
Filename := ExtractFilePath(Paramstr(0)) + 'program.ini';
MyIniFile := TInifile.Create(Filename);
try
EdtServer.Text := MyIniFile.ReadString('ServerAddress', 'ServerName', '.');
Edit1.Text := MyIniFile.ReadString('ServerAddress', 'count', '100');
Edit2.Text := MyIniFile.ReadString('ServerAddress', 'row', '1');
EdtPsd.Text := MyIniFile.ReadString('ServerAddress', 'psd', 'mymsserver');
edtName.Text := MyIniFile.ReadString('ServerAddress', 'name', 'wlms');
finally
FreeAndNil(MyIniFile);
end;
end;procedure TForm1.btLogClick(Sender: TObject);
begin
if (EdtServer.Text = '') then
begin
ShowMessage('输入服务器地址!');
exit;
end;
ADOQCon.Connected := False;
ADOQCon.ConnectionString := '';
try
ADOQCon.ConnectionString := 'Provider=SQLOLEDB.1;Password=' + EdtPsd.Text + ';Persist Security Info=True;User ID=' + edtName.Text + ';Initial Catalog= master;Data Source=' + EdtServer.Text +
';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=' + EdtServer.Text + ';Use Encryption for Data=False;Tag with column collation when possible=False'; ADOQCon.Connected := True;
ADOQCon.Connected := true;
ADOQServerList.Connection := ADOQCon;
ADOQServerList.Open;
ADOQServerList.First;
ComboBox1.Items.Clear;
while not ADOQServerList.Eof do
begin
ComboBox1.Items.Add(ADOQServerList.FieldValues['name']);
ADOQServerList.Next;
end;
ShowMessage('连接成功!');
ADOQCon.Connected := False;
// ADOQTable.Connection := ADOQCon;
// s_cmd := 'select o.name,i.rows ID' + #13#10 +
// 'from sysobjects o,sysindexes i' + #13#10 +
// 'where o.id=i.id and o.Xtype=''U'' and i.indid<2' + #13#10;
// s_cmd := s_cmd + ' and i.rows >='+inttostr(StrToIntDef(edit2.Text,-1));
// ADOQTable.SQL.Text := s_cmd + ' order by o.name';
// ADOQTable.Open;
except
ShowMessage('连接不正常!');
end;end;procedure TForm1.btExitClick(Sender: TObject);
begin
ADOQCon.Connected := false;
Close;
end;procedure TForm1.cxGrid2DBTableView1CellClick(
Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
var
BandColumn: TcxGridDBColumn;
i: Integer;
begin
try
for i := cxGrid1DBTableView1.ColumnCount - 1 downto 0 do
begin
cxGrid1DBTableView1.Columns[i].Destroy;
end;
ADOQList.Connection := ADOQCon;
ADOQFieldList.Connection := ADOQCon;
ADOQList.SQL.Text := 'SELECT TOP ' + edit1.text + ' * FROM [' + ADOQTable.FieldValues['name'] + ']';
ADOQList.Open;
for I := 0 to ADOQList.FieldCount - 1 do
begin
BandColumn := cxGrid1DBTableView1.CreateColumn;
BandColumn.Caption := ADOQList.Fields.Fields[I].FieldName;
BandColumn.DataBinding.FieldName := ADOQList.Fields.Fields[I].FieldName;
BandColumn.Width := 100;
end;
ADOQFieldList.SQL.Text := 'declare @TableName varchar(255) , @script_type char(1)' + #13#10 +
'----------------------------------------' + #13#10 +
'-- 参数' + #13#10 +
'----------------------------------------' + #13#10 +
'set @TableName = ''' + ADOQTable.FieldValues['name'] + '''' + #13#10 +
'----------------------------------------' + #13#10 +
'declare @str varchar(8000) ' + #13#10 +
'set @str = '''' ' + #13#10 +
'select cols.colorder as 序号,' + #13#10 +
'''['' + cols.name + ''] ''as 列名,' + #13#10 +
'type.name+ ( case when cols.xtype in (165,167,173,175,231,239)' + #13#10 +
'then ''(''+ convert(varchar(10) , cols.prec) + '')''' + #13#10 +
'when cols.xtype in (106,108)' + #13#10 +
'then ''(''+ convert(varchar(10) , cols.prec)+'' , '' + convert(varchar(10) ,cols.scale)+ '') ''' + #13#10 +
'else '''' end ) as 列类型,' + #13#10 +
'case isnull(cols.collation,''a'') when ''a'' then '''' else ''COLLATE ''+cols.collation end 排序,' + #13#10 +
'case cols.isnullable when 1 then ''NULL'' ELSE ''NOT NULL'' END as 为空,' + #13#10 +
'isnull(com.text,'''') 默认值,' + #13#10 +
'isnull (d.[value],'''' ) as 字段说明,' + #13#10 +
'case when COLUMNPROPERTY (cols.id,cols.name,''isidentity'') = 1 then ''√'' else '''' end 标识,' + #13#10 +
'( case when (' + #13#10 +
'select count(*) from sysobjects' + #13#10 +
'where name in (' + #13#10 +
'select name from sysindexes where (id = cols.id ) and ( indid in' + #13#10 +
'(select indid from sysindexkeys where' + #13#10 +
'( id = cols.id ) and ( colid in (' + #13#10 +
'select colid from syscolumns' + #13#10 +
'where ( id = cols.id ) and ( name = cols.name ))))))' + #13#10 +
'and ( xtype =''PK'')) > 0 then ''√'' else '''' end ) 主键' + #13#10 +
'from syscolumns cols' + #13#10 +
'left join systypes type' + #13#10 +
'on cols.xtype = type.xtype and cols.xtype = type.xusertype left join syscomments com on cols.cdefault=com.id left join sysproperties d on cols.id=d.id and cols.colid=d.smallid' + #13#10 +
'where cols.id = (select id from sysobjects where name = @TableName) ';
Memo1.Text:=ADOQFieldList.SQL.Text;
ADOQFieldList.Open;
except
ShowMessage('查询出错!');
end;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
FileName: string;
MyIniFile: TInifile;
begin
Filename := ExtractFilePath(Paramstr(0)) + 'program.ini';
MyIniFile := TInifile.Create(Filename);
try
MyIniFile.writestring('ServerAddress', 'ServerName', EdtServer.Text);
MyIniFile.writestring('ServerAddress', 'count', Edit1.Text);
MyIniFile.writestring('ServerAddress', 'row', Edit2.Text);
MyIniFile.writestring('ServerAddress', 'psd', EdtPsd.Text);
MyIniFile.writestring('ServerAddress', 'name', edtName.Text);
finally
FreeAndNil(MyIniFile);
end;
end;procedure TForm1.ComboBox1Change(Sender: TObject);
var
s_cmd: string;
begin
if ComboBox1.Text = '' then
exit;
try
ADOQCon.Connected := false;
ADOQCon.ConnectionString := '';
ADOQCon.ConnectionString := 'Provider=SQLOLEDB.1;Password=' + EdtPsd.Text + ';Persist Security Info=True;User ID=' + edtName.Text + ';Initial Catalog= ' + ComboBox1.Text + ';Data Source=' + EdtServer.Text +
';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=' + EdtServer.Text + ';Use Encryption for Data=False;Tag with column collation when possible=False'; ADOQCon.Connected := True;
ADOQCon.Connected := True;
ADOQTable.Connection := ADOQCon;
s_cmd := 'select o.name,i.rows ID' + #13#10 +
'from sysobjects o,sysindexes i' + #13#10 +
'where o.id=i.id and o.Xtype=''U'' and i.indid<2' + #13#10;
s_cmd := s_cmd + ' and i.rows >=' + inttostr(StrToIntDef(edit2.Text, -1));
ADOQTable.SQL.Text := s_cmd + ' order by o.name';
ADOQTable.Open;
except
ShowMessage('连接不正常!');
end;
end;end.