主题:以下代码出错 急救!!!
'Public fMainForm As frmMain
Public flag As Integer '登录成功标志
Public bflagadd As Integer '书籍操作标志
Public flagadd As Integer '读者操作标志
Public brflagadd As Integer '借还书标志
Public FileName As String '图片文件名
Public Sub SaveToDB(diskFile As String, jszh As String)
Dim byteData() As Byte '定义数据块数组
Dim NumBlocks As Long '定义数据块个数
Dim FileLength As Long '标识文件长度
Dim LeftOver As Long '定义剩余字节长度
Dim SourceFile As Long '定义自由文件号
Dim i As Long '定义循环变量
Const BLOCKSIZE = 4096
Dim cnn As ADODB.Connection
Dim ADORst As New ADODB.Recordset 'ADODB Recordset 对象
Dim Fld As ADODB.Field 'ADODB Field 对象
Set cnn = New ADODB.Connection
cnn.Open ConnectString
ADORst.Open "AHC_XS", cnn, adOpenDynamic, adLockOptimistic '打开一个ADO动态集 表名为table
Do While Trim(ADORst("借书证号").Value) <> Trim(jszh) And Not ADORst.EOF
ADORst.MoveNext
Loop
If Not ADORst.EOF Then
Set Fld = ADORst("照片")
Else
Exit Sub
End If
SourceFile = FreeFile '提供一个尚未使用的文件号
Open diskFile For Binary Access Read As SourceFile '打开文件
FileLength = LOF(SourceFile) '得到文件长度
If FileLength = 0 Then '判断文件是否存在
Close SourceFile
MsgBox diskFile & " 无 内 容 或 不 存 在 !"
Else
NumBlocks = FileLength \ BLOCKSIZE '得到数据块的个数
LeftOver = FileLength Mod BLOCKSIZE '得到剩余字节数
Fld.Value = Null
ReDim byteData(BLOCKSIZE) '重新定义数据块的大小
For i = 1 To NumBlocks
Get SourceFile, , byteData() ' 读到内存块中
Fld.AppendChunk byteData() '写入FLD
Next i
ReDim byteData(LeftOver) '重新定义数据块的大小
Get SourceFile, , byteData() '读到内存块中
Fld.AppendChunk byteData() '写入FLD
Close SourceFile '关闭源文件
ADORst!FileLen = FileLength
ADORst.Update
ADORst.Close
cnn.Close
End If
End Sub
Public Sub getfromDB(diskFile As String, jszh As String)
Dim byteData() As Byte '定义数据块数组
Dim NumBlocks As Long '定义数据块个数
Dim FileLength As Long '标识文件长度
Dim LeftOver As Long '定义剩余字节长度
Dim SourceFile As Long '定义自由文件号
Dim i As Long '定义循环变量
Const BLOCKSIZE = 4096
Dim cnn As ADODB.Connection
Dim ADORst As New ADODB.Recordset 'ADODB Recordset 对象
Dim Fld As ADODB.Field 'ADODB Field 对象
Set cnn = New ADODB.Connection
cnn.Open ConnectString
ADORst.Open "AHC_XS", cnn, adOpenDynamic, adLockOptimistic '打开一个ADO动态集 表名为table
Do While Trim(ADORst("借书证号").Value) <> Trim(jszh) And Not ADORst.EOF
ADORst.MoveNext
Loop
If Not ADORst.EOF Then
Set Fld = ADORst("照片")
Else
Exit Sub
End If
SourceFile = FreeFile '提供一个尚未使用的文件号
Open diskFile For Binary As SourceFile '打开文件
FileLength = ADORst!FileLen '得到文件长度
If IsNull(FileLength) Or FileLength = 0 Then '判断文件是否存在
Close SourceFile
MsgBox diskFile & " 无 内 容 或 不 存 在 !"
Else
NumBlocks = FileLength \ BLOCKSIZE '得到数据块的个数
LeftOver = FileLength Mod BLOCKSIZE '得到剩余字节数
ReDim byteData(BLOCKSIZE) '重新定义数据块的大小
For i = 1 To NumBlocks
byteData() = Fld.GetChunk(BLOCKSIZE) '读取FLD
Put SourceFile, , byteData() ' 写数据到文件
Next i
ReDim byteData(LeftOver) '重新定义数据块的大小
byteData() = Fld.GetChunk(LeftOver) '读取FLD
Put SourceFile, , byteData() ' 写数据到文件
Close SourceFile '关闭源文件
ADORst.Close
cnn.Close
End If
End Sub
Sub main()
flag = 0
frmMain.Show
End Sub
Public Function ConnectString() As String '返回连接数据源的字符串
ConnectString = "FileDSN=AHCXSBOOK.dsn;UID=sa;PWD=''"
End Function
'根据参数传递的SQL语句,执行一个查询,并返回结果集
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
[color=FF0000]cnn.Open ConnectString[/color]
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
End Function
Public Sub EnterToTab(Keyasc As Integer) '利用TAB可以提高系统的可操作性
If Keyasc = 13 Then
SendKeys "{TAB}"
End If
End Sub
[b]运行时总是提示无效的DSN[/b],上方红字处出错!!!!无解啊
Public flag As Integer '登录成功标志
Public bflagadd As Integer '书籍操作标志
Public flagadd As Integer '读者操作标志
Public brflagadd As Integer '借还书标志
Public FileName As String '图片文件名
Public Sub SaveToDB(diskFile As String, jszh As String)
Dim byteData() As Byte '定义数据块数组
Dim NumBlocks As Long '定义数据块个数
Dim FileLength As Long '标识文件长度
Dim LeftOver As Long '定义剩余字节长度
Dim SourceFile As Long '定义自由文件号
Dim i As Long '定义循环变量
Const BLOCKSIZE = 4096
Dim cnn As ADODB.Connection
Dim ADORst As New ADODB.Recordset 'ADODB Recordset 对象
Dim Fld As ADODB.Field 'ADODB Field 对象
Set cnn = New ADODB.Connection
cnn.Open ConnectString
ADORst.Open "AHC_XS", cnn, adOpenDynamic, adLockOptimistic '打开一个ADO动态集 表名为table
Do While Trim(ADORst("借书证号").Value) <> Trim(jszh) And Not ADORst.EOF
ADORst.MoveNext
Loop
If Not ADORst.EOF Then
Set Fld = ADORst("照片")
Else
Exit Sub
End If
SourceFile = FreeFile '提供一个尚未使用的文件号
Open diskFile For Binary Access Read As SourceFile '打开文件
FileLength = LOF(SourceFile) '得到文件长度
If FileLength = 0 Then '判断文件是否存在
Close SourceFile
MsgBox diskFile & " 无 内 容 或 不 存 在 !"
Else
NumBlocks = FileLength \ BLOCKSIZE '得到数据块的个数
LeftOver = FileLength Mod BLOCKSIZE '得到剩余字节数
Fld.Value = Null
ReDim byteData(BLOCKSIZE) '重新定义数据块的大小
For i = 1 To NumBlocks
Get SourceFile, , byteData() ' 读到内存块中
Fld.AppendChunk byteData() '写入FLD
Next i
ReDim byteData(LeftOver) '重新定义数据块的大小
Get SourceFile, , byteData() '读到内存块中
Fld.AppendChunk byteData() '写入FLD
Close SourceFile '关闭源文件
ADORst!FileLen = FileLength
ADORst.Update
ADORst.Close
cnn.Close
End If
End Sub
Public Sub getfromDB(diskFile As String, jszh As String)
Dim byteData() As Byte '定义数据块数组
Dim NumBlocks As Long '定义数据块个数
Dim FileLength As Long '标识文件长度
Dim LeftOver As Long '定义剩余字节长度
Dim SourceFile As Long '定义自由文件号
Dim i As Long '定义循环变量
Const BLOCKSIZE = 4096
Dim cnn As ADODB.Connection
Dim ADORst As New ADODB.Recordset 'ADODB Recordset 对象
Dim Fld As ADODB.Field 'ADODB Field 对象
Set cnn = New ADODB.Connection
cnn.Open ConnectString
ADORst.Open "AHC_XS", cnn, adOpenDynamic, adLockOptimistic '打开一个ADO动态集 表名为table
Do While Trim(ADORst("借书证号").Value) <> Trim(jszh) And Not ADORst.EOF
ADORst.MoveNext
Loop
If Not ADORst.EOF Then
Set Fld = ADORst("照片")
Else
Exit Sub
End If
SourceFile = FreeFile '提供一个尚未使用的文件号
Open diskFile For Binary As SourceFile '打开文件
FileLength = ADORst!FileLen '得到文件长度
If IsNull(FileLength) Or FileLength = 0 Then '判断文件是否存在
Close SourceFile
MsgBox diskFile & " 无 内 容 或 不 存 在 !"
Else
NumBlocks = FileLength \ BLOCKSIZE '得到数据块的个数
LeftOver = FileLength Mod BLOCKSIZE '得到剩余字节数
ReDim byteData(BLOCKSIZE) '重新定义数据块的大小
For i = 1 To NumBlocks
byteData() = Fld.GetChunk(BLOCKSIZE) '读取FLD
Put SourceFile, , byteData() ' 写数据到文件
Next i
ReDim byteData(LeftOver) '重新定义数据块的大小
byteData() = Fld.GetChunk(LeftOver) '读取FLD
Put SourceFile, , byteData() ' 写数据到文件
Close SourceFile '关闭源文件
ADORst.Close
cnn.Close
End If
End Sub
Sub main()
flag = 0
frmMain.Show
End Sub
Public Function ConnectString() As String '返回连接数据源的字符串
ConnectString = "FileDSN=AHCXSBOOK.dsn;UID=sa;PWD=''"
End Function
'根据参数传递的SQL语句,执行一个查询,并返回结果集
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
[color=FF0000]cnn.Open ConnectString[/color]
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
End Function
Public Sub EnterToTab(Keyasc As Integer) '利用TAB可以提高系统的可操作性
If Keyasc = 13 Then
SendKeys "{TAB}"
End If
End Sub
[b]运行时总是提示无效的DSN[/b],上方红字处出错!!!!无解啊