- ©«¤l
- 9
- ¥DÃD
- 6
- ºëµØ
- 0
- ¿n¤À
- 22
- ÂI¦W
- 0
- §@·~¨t²Î
- XP
- ³nÅ骩¥»
- XP
- ¾\ŪÅv
- 10
- ©Ê§O
- ¨k
- ¨Ó¦Û
- TAIWAN
- µù¥U®É¶¡
- 2011-9-12
- ³Ì«áµn¿ý
- 2016-5-4
|
[µo°Ý] ±NExcel·í¤¤ªº¸ê®ÆÂà¤J¸ê®Æ®w¤¤·|¥X²{¨Ï¥ÎªÌ¦Ûq«¬ºA©|¥¼©w¸q
½Ð°Ý³oÓ¤Ö¤F¤°»ò?
Sub Export2Mysql()
'±NExcel·í¤¤ªº¸ê®ÆÂà¤J¸ê®Æ®w¤¤
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim fld As ADODB.Field
Dim sql As String
Set conn = New ADODB.Connection
'³o¸Ìn´«¦¨§Aªº¦øªA¾¹ ®w¦W ¥Î¤á¦W ±K½X
conn.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};" & "SERVER=xxx.xxx.xxx.xxx;" & " DATABASE=test;" & "UID=test WD=password; OPTION=3"
conn.Open
'·Ç³Æ³Ð«Øªí
conn.Execute "drop table if exists test"
'ª`·N³o¸Ìªº¦U¦CÃþ«¬³]©w
conn.Execute "create table test(name text,pass text)"
'«ö¦æ¾É¤J,³o¸Ì°²³]²Ä¤@¦C¦sªº¬Oname¡A²Ä¤G¦C¦sªº¬Opass
For i = 1 To 20
conn.Execute "insert into test(name,pass) values('" & Cells(i, 1).Text & "','" & Cells(i, 2) & "')"
Next i
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
'¨Ï¥Î¤U±ªº¥N½XÅçÃÒ
rs.Open "select * from test", conn
rs.MoveFirst
Do Until rs.EOF
For Each fld In rs.Fields
Debug.Print fld.Value,
Next
rs.MoveNext
Debug.Print
Loop
rs.Close
conn.Close
End Sub |
|