易截截图软件、单文件、免安装、纯绿色、仅160KB

执行SQL文,生成EXCEL

''' <summary>
''' SQL文執行結果のEXCEL出力
''' </summary>
''' <param name="connString">OLEDB接続文字列</param>
''' <param name="sqlString">SQL文</param>
''' <param name="savePath">出力ファイルパス</param>
''' <remarks></remarks>
Public Shared Sub ExecSqlToExcel(ByVal connString As String, ByVal sqlString As String, _
ByVal savePath As String)
Dim mExcelApplication As Excel.Application = Nothing
Dim mWorkbook As Excel.Workbook = Nothing
Dim mWorkSheet As Excel.Worksheet = Nothing
Dim mQueryTable As Excel.QueryTable = Nothing
Try
mExcelApplication = New Excel.Application()
mWorkbook = mExcelApplication.Workbooks.Add
mWorkSheet = mWorkbook.Sheets(1)
mQueryTable = mWorkSheet.QueryTables.Add(connString, mWorkSheet.Range("A1"), sqlString)
mQueryTable.FieldNames = True
mExcelApplication.DisplayAlerts = False
mQueryTable.Refresh()
mWorkbook.SaveAs(savePath)
Catch ex As Exception
Throw ex
Finally
If Not mWorkSheet Is Nothing Then
mQueryTable = Nothing
mWorkbook.Close()
mWorkbook = Nothing
mExcelApplication = Nothing
End If
End Try
End Sub
说明:
connString="OLEDB;Provider=SQLOLEDB;server=xxx;uid=xxx;pwd=xxx;Initial Catalog=xxx"
savePath应该是完整的路径(含文件名)
导出的excel没有格式要求,如果有必要,可以通过vba对该对象进行格式操作
第一行是select的字段名,如果想要汉字形式,则给每个字段加上汉字别名即可


相关文档:

[收拢] 用sqlite 执行标准 sql 语法

http://www.umgr.com/blog/PostView.aspx?bpId=36294
 1. 执行sql语句
int sqlite3_exec(sqlite3*, const char *sql, sqlite3_callbacksql 语法
, void *,  char **errmsg );
这就是执行一条 sql 语句的函数。
第1个参数不再说了,是前面open函数得到的指针。说了是关键数据结构。
第2个参数const char ......

使用SQLServer模板来写规范的SQL语句

如果你经常遇到下面的问题,你就要考虑使用SQL Server的模板来写规范的SQL语句了:
SQL初学者。
经常忘记常用的DML或是DDL SQL 语句。
在多人开发维护的SQL中,每个人都有自己的SQL习惯,没有一套统一的规范。
在SQL Server Management Studio中,已经给大家提供了很多常用的现成SQL规范模板。
SQL Server Management ......

oracle sql优化之多表连接优化


Use equality first.
使用等连接
Use range operators only where equality does not apply.
只有在等连接不可用的情况下事由区间连接
Avoid use of negatives in the form of !=
or NOT.
避免使用 != 或者 not
Avoid LIKE pattern matching.
避免使用 LIKE匹配
Try to retrieve specific rows and in small n ......

Access数据库字段类型说明以及与SQL之间的对照关系

文本 nvarchar(n)
备注 ntext
数字(长整型) int
数字(整型) smallint
数字(单精度) real
数字(双精度) float
数字(字节) tinyint
货币 money
日期 smalldatetime
布尔 bit
附:转换成SQL的脚本。
ALTER TABLE tb ALTER COLUMN aa Byte 数字[字节]
ALTER TABLE tb ALTER COLUMN aa Long 数字[长整型]
ALTER T ......

Sql server中 DateAdd、DateDiff用法

 这个函数DateAdd(month,2,WriteTime):
日期部分缩写 Year yy, yyyy quarter qq, q Month mm, m dayofyear dy, y Day dd, d Week wk, ww Hour hh minute mi, n second ss, s millisecond ms
  这个表足够说明问题了吧,从year到millisecond都可以处理,够方便了吧.
DATEDIFF 函数 [日期和时间]
-------------- ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号