Delphi Excel to Sql Server
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids, DB, ADODB,comobj, OleServer,
ExcelXP;
type
TForm1 = class(TForm)
ADOConn: TADOConnection;
atblXlsToSql: TADOTable;
DBGrid1: TDBGrid;
Panel1: TPanel;
Button1: TButton;
opdExcel: TOpenDialog;
DataSource1: TDataSource;
Excel: TExcelApplication;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function ConnectDB:boolean; //连接数据库
function OpenTable(const Tablename:String):boolean; //打开指定数据表
function XlsToSqlTable(const xlsFileName,TableName:String):boolean; //将Excel数据导入Sql Server
public
{ Public declarations }
end;
var
Form1: TForm1;
serverIP,dbName,userid,passw:string; //服务器IP,数据库名称,用户名,密码
implementation
{$R *.dfm}
function TForm1.ConnectDB:boolean;
begin
Result:=false;
serverIP:='192.168.0.0';
dbName:='OnLine';
userid:='sa';
passw:='sa';
if not adoconn.Connected then
begin
adoconn.ConnectionString:='Provider=SQLOLEDB.1;Password=' + passw
+ ';Persist Security Info=True;User ID=' + userid
+ ';Initial Ca
相关文档:
Next up in the Inside the Storage Engine series is a discussion of page structure. Pages exist to store records. A database page is an 8192-byte (8KB) chunk of a database data file. They are aligned on 8KB boundaries within the data files, starting at byte-offset ......
以前在安装sql的时候,如此提示,我只要重新启动即可,可是今天重新启动了N次计算机,问题却丝毫没有解决,依然提示这样的话。“以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机。” 只好google以下,最终得知是安装程序在先前的安装过程中 ......
select ID,Item1,Item2,Item3,Item4
into #Temp
from (
select ID='200910',Item1='A',Item2='B',Item3='C',Item4='T1'
union all
select ID='200910',Item1='',Item2='B',Item3='C' ,Item4='G2'
union all
select ID='200910',Item1='A',Item2='D',Item3='C' ,Item4='T3'
union all
select ID='200910',Item ......
--从Excel文件中,导入数据到SQL数据库中,很简单,直接用下面的语句:
/*===================================================================*/
--如果接受数据导入的表已经存在
insert into 表 select * from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$)
--如 ......