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 '连接到数据库 |
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 '服务器名 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 '连接到数据库 |
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 '返回一个 Integer,代表下一个可供Open语句使用的文件号 Open filePath For Binary Access Read As file_num '打开磁盘文件 filelen = LOF(file_num) '求文件长度 ReDim DataArr(filelen) '根据文件长度定义动态数组大小 Get sourcefile, , DataArr '将一个已打开的磁盘文件读入数组变量之中 adofld.AppendChunk DataArr() '将数组内容存入image型字段中 Close file_num '关闭磁盘文件 adorst.update |
dim FileArr () As Byte, current as string filelen = office_rst.Fields("office").ActualSize '得到office字段中的文件数据的大小 ReDim FileArr(filelen) FileArr() = office_rst.Fields("office").GetChunk(filelen) '将字段中数据写入动态数组中 bufferfile = FreeFile Open "tempfile" For Binary Access Read Write As bufferfile '打开一个临时文件 Put bufferfile, ,FileArr '将动态数组FileArr中的数据写入临时文件tempfile中 current = CurDir & "\tempfile" '获取临时文件的全路径 WebBrowOff.Navigate current '在WebBrowser控件中显示文件内容 |