Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist;Security Info=False;Initial Catalog=Science_File;Data Source=Data_Server |
dim odbcstr as String, adocon As New ADODB.Connection odbcstr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;_ Initial Catalog=Science_File;Data Source=Data_Server" adocon.Open odbcstr '連接到數(shù)據(jù)庫 |
Private Declare Function NetServerEnum Lib "netapi32" _ (lpServer As Any, ByVal lLevel As Long, vBuffer As Any, _ lPreferedMaxLen As Long, lEntriesRead As Long, lTotalEntries As Long, _ ByVal lServerType As Long, ByVal sDomain$, vResume As Any) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination _ As Any, Source As Any, ByVal Length As Long) Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long Private Type SV_100 platform As Long name As Long End Type dim sv100 As SV_100, nRet As Long, i as long, lServerInfo As Long dim lServerInfo As Long, lPreferedMaxLen As Long, lEntriesRead As Long dim lTotalEntries As Long, sDomain As String, vResume As Variant dim buffer() As Byte, nLen As Long lPreferedMaxLen = 65536 nRet = NetServerEnum(0, 101, lServerInfo, lPreferedMaxLen, lEntriesRead, lTotalEntries, 4, sDomain, vResume) If nRet = 0 Or nRet = 234& Then For i = 0 To lEntriesRead - 1 CopyMemory sv100, ByVal lServerInfo, Len(sv100) nLen = lstrlenW(sv100.name) * 2 If nLen Then ReDim buffer(0 To (nLen - 1)) As Byte CopyMemory buffer(0), ByVal sv100.name, nLen End If Combo1.List(i) = buffer '服務(wù)器名 lServerInfo = lServerInfo + 24 Next i End If |
odbcstr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;_ Initial Catalog=Science_File;Data Source=" & Form2.Combo1.Text adocon.Open odbcstr '連接到數(shù)據(jù)庫 |
dim office_rst As New ADODB.Recordset adocon.CursorLocation = adUseClient office_rst.Open "office", adocon, adOpenDynamic, adLockOptimistic, adCmdTable |
dim adofld As ADODB.Field, DataArr() As Byte, filelen As Long, file_num As Long office_rst.AddNew Set adofld = office_rst("office") adorst("filename").Value = filePath file_num = FreeFile '返回一個(gè) Integer,代表下一個(gè)可供Open語句使用的文件號(hào) Open filePath For Binary Access Read As file_num '打開磁盤文件 filelen = LOF(file_num) '求文件長度 ReDim DataArr(filelen) '根據(jù)文件長度定義動(dòng)態(tài)數(shù)組大小 Get sourcefile, , DataArr '將一個(gè)已打開的磁盤文件讀入數(shù)組變量之中 adofld.AppendChunk DataArr() '將數(shù)組內(nèi)容存入image型字段中 Close file_num '關(guān)閉磁盤文件 adorst.update |
dim FileArr () As Byte, current as string filelen = office_rst.Fields("office").ActualSize '得到office字段中的文件數(shù)據(jù)的大小 ReDim FileArr(filelen) FileArr() = office_rst.Fields("office").GetChunk(filelen) '將字段中數(shù)據(jù)寫入動(dòng)態(tài)數(shù)組中 bufferfile = FreeFile Open "tempfile" For Binary Access Read Write As bufferfile '打開一個(gè)臨時(shí)文件 Put bufferfile, ,F(xiàn)ileArr '將動(dòng)態(tài)數(shù)組FileArr中的數(shù)據(jù)寫入臨時(shí)文件tempfile中 current = CurDir & "\tempfile" '獲取臨時(shí)文件的全路徑 WebBrowOff.Navigate current '在WebBrowser控件中顯示文件內(nèi)容 |