Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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µÄ×Ö¶ÎÃû£¬Èç¹ûÏëÒªºº×ÖÐÎʽ£¬Ôò¸øÿ¸ö×ֶμÓÉϺº×Ö±ðÃû¼´¿É


Ïà¹ØÎĵµ£º

ʹÓÃSQLServerÄ£°åÀ´Ð´¹æ·¶µÄSQLÓï¾ä

Èç¹ûÄã¾­³£Óöµ½ÏÂÃæµÄÎÊÌ⣬Äã¾ÍÒª¿¼ÂÇʹÓÃSQL ServerµÄÄ£°åÀ´Ð´¹æ·¶µÄSQLÓï¾äÁË£º
SQL³õѧÕß¡£
¾­³£Íü¼Ç³£ÓõÄDML»òÊÇDDL SQL Óï¾ä¡£
ÔÚ¶àÈË¿ª·¢Î¬»¤µÄSQLÖУ¬Ã¿¸öÈ˶¼ÓÐ×Ô¼ºµÄSQLÏ°¹ß£¬Ã»ÓÐÒ»Ì×ͳһµÄ¹æ·¶¡£
ÔÚSQL Server Management StudioÖУ¬ÒѾ­¸ø´ó¼ÒÌṩÁ˺ܶೣÓõÄÏÖ³ÉSQL¹æ·¶Ä£°å¡£
SQL Server Management ......

(ת)SQL ²éÕÒÖظ´¼Ç¼

±ístuinfo£¬ÓÐÈý¸ö×Ö¶Îrecno(×ÔÔö),stuid,stuname
½¨¸Ã±íµÄSqlÓï¾äÈçÏ£º
CREATE TABLE [StuInfo] (
[recno] [int] IDENTITY (1, 1) NOT NULL ,
[stuid] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[stuname] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
1.--²éijһÁ ......

JSP·ÀSQL×¢Èë¹¥»÷

µÚÒ»ÖÖ²ÉÓÃÔ¤±àÒëÓï¾ä¼¯£¬ËüÄÚÖÃÁË´¦ÀíSQL×¢ÈëµÄÄÜÁ¦£¬Ö»ÒªÊ¹ÓÃËüµÄsetString·½·¨´«Öµ¼´¿É£º
String sql= "select * from users where username=? and password=?;
PreparedStatement preState = conn.prepareStatement(sql);
preState.setString(1, userName);
preState.setString(2, password);
ResultSet rs = ......

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 º¯Êý [ÈÕÆÚºÍʱ¼ä]
-------------- ......

ʵÑéÎå SQL²éѯ£¨ÅÅÐò¡¢¼¯º¯ÊýºÍ·Ö×é×Ó¾äµÄÓ¦Óã©

ÊÔÑéÄ¿µÄ:
Ò»¡¢Ñ§Ï°²éѯ½á¹ûµÄÅÅÐò
¶þ¡¢Ñ§Ï°Ê¹Óü¯º¯ÊýµÄ·½·¨£¬Íê³Éͳ¼Æ
µÈ²éѯ¡£
Èý¡¢Ñ§Ï°Ê¹Ó÷Ö×é×Ó¾ä
Ò»¡¢Ñ§Ï°²éѯ½á¹ûµÄÅÅÐò
1¡¢²éѯȫÌåѧÉúÐÅÏ¢£¬½á¹û°´ÕÕÄêÁä½µ
ÐòÅÅÐò
select *
from student
order by sage desc
2¡¢²éѯѧÉúÑ¡ÐÞÇé¿ö£¬½á¹ûÏÈ°´ÕտγÌ
ºÅÉýÐòÅÅÐò£¬ÔÙ°´³É¼¨½µÐòÅÅÐò
select *
from ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ