这样应该可以吧例如: SELECT * INTO XLImport5 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\test\xltest.xls', 'SELECT 姓名,编号 FROM [Customers$]') 参考 http://support.microsoft.com/kb/321686/zh-cn
如果哪程序写,就连接Excel把它当作数据源只能提供点片段代码,供你参考和思考 SQL := 'INSERT INTO '+TableName+'('+strName+') VALUES('+strValue+')'; ado := TADOQuery.Create(nil); try ado.Connection := adoConn; ado.CursorLocation := clUseServer; ado.SQL.Clear; ado.SQL.Add(SQL); ado.Prepared; try for col:=0 to High(Fields) do ado.Parameters.ParamByName(Fields[col].FieldName).Value := Fields[col].FieldValue; Result := ado.ExecSQL>0; except //on e: Exception do // ShowError(FormatDateTime('yyyy-mm-dd hh:mm:ss',Now)+e.Message); end; finally FreeAndNil(ado); end;
1.//装载Excel与MSSQL的字段中介表,QIntroduce;
2.SQL字段变量A,Excel字段变量B
3.循环中介表
4.SQL.FieldByName(A).Asstring:=Excel.FieldByName(B).Asstring;
EnFieldName ChFieldName
bh 编号
然后写个函数,类似如下
GetEnFieldName(ChFieldName:String):Stirng;导数据的时候调用一下!
SELECT * INTO XLImport5 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', 'SELECT 姓名,编号 FROM [Customers$]')
参考
http://support.microsoft.com/kb/321686/zh-cn
ado := TADOQuery.Create(nil);
try
ado.Connection := adoConn;
ado.CursorLocation := clUseServer;
ado.SQL.Clear;
ado.SQL.Add(SQL);
ado.Prepared;
try
for col:=0 to High(Fields) do
ado.Parameters.ParamByName(Fields[col].FieldName).Value := Fields[col].FieldValue;
Result := ado.ExecSQL>0;
except
//on e: Exception do
// ShowError(FormatDateTime('yyyy-mm-dd hh:mm:ss',Now)+e.Message);
end;
finally
FreeAndNil(ado);
end;