Visual Basic数据库开发疑难问题解

资讯 驱动中国 sevenleaf 2,649 次阅读 0 条评论
分享 Q

      问:如何显示格式为03-3-13的日期?
      解决的方法:

1
Cmd.CommandText = "select * from 支出 where 日期=03-3-13" 中 03-3-13=-13。
日期实际上是Double型数字。0 是 1899-12-30,-13 是 1899-12-17。你当然没有这样日期的记录,所以只有大于才行。
2
Cmd.CommandText = "select * from 支出 where 日期=#03-3-13#"
凡是没有明示,文字型日期是按美国习惯解释的,#03-3-13# 是 0013-03-03。
或者使用长日期格式:
Cmd.CommandText = "select * from 支出 where 日期=#2003-3-13#"
用格式化函数:
Cmd.CommandText = "select * from 支出 where 日期=#" & format(mydate,"yyyy-mm-dd") & "#"
      问: 如何判断DNS是否存在?怎样才能列举出所有的DNS?
      解决方法:
      1、通过利用ODBC API中的SQLDataSource函数可以取得ODBC API中数据源的列表。 判断DNS是否存在:
      2、使用API函数Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv As Long, ByVal fDirection As Integer, ByVal szDSN As String, ByVal cbDSNMax As Integer, pcbDSN As Integer, ByVal szDescription As String, ByVal cbDescriptionMax As Integer, pcbDescription As Integer) As Integer Private Declare Function SQLAllocEnv Lib "ODBC32.DLL" (ByRef env As Long) As Long 列举出所有DNS。
      问:处理文本文件是导入数据库还是直接读写文件呢? 
      解决方法:
Set main = bumony.OpenRecordset("main")
Open App.Path & "\sources\" & Text1.Text & "\´úÀíÒµÎñ" & Text1.Text & ".txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str1
With main
.AddNew
!code = Mid(str1, 1, 5)
!date = Text1.Text
If Mid(str1, 1, 5) = "21310" Or Mid(str1, 1, 5) = "21311" Or Mid(str1, 1, 5) = "21410" Or Mid(str1, 1, 5) = "21411" Then
!Money = Trim(Mid(str1, 7, 10))
Else
!Money = Trim(Mid(str1, 7, 10)) & "0000"
End If
!whao = "1102"
!ywhao = "1102"
.Update
End With
Loop
Close #1
main.Close
      问:调用SQL存储后有参数返回,应该怎么赋值?
      解决方法:
Dim ADOCmd As New ADODB.Command
Dim ADOPrm As New ADODB.Parameter
Dim ADORs As ADODB.Recordset
....
Set ADOCmd.ActiveConnection = ADOCon
With ADOCmd
.CommandType = adCmdStoredProc
.CommandText = "ADOTestRPE"
End With
sParmName = "Output"
Set ADOPrm = ADOCmd.CreateParameter(sParmName, adInteger, adParamOutput)
ADOCmd.Parameters.Append ADOPrm
ADOCmd.Parameters(sParmName).Value = 999
Set ADORs = ADOCmd.Execute
.....
Debug.Print "Output: " & ADOCmd.Parameters("Output").Value
      问: SQL Server 2000中如何存取图片信息?
      解决方法:
新建一个工程,添加 ado 控件,2个 Command ,1个 Picture,1个 Image
Dim Chunk() As Byte
Dim lngLengh As Long
Dim intChunks As Integer
Dim intFragment As Integer
Const ChunkSize = 1000
Const lngDataFile = 1
Private Sub cmdBrowse_Click()
On Error Resume Next
With cmdlFilePath
.Filter = "JPG Files|*.JPG|Bitmaps|*.BMP"
.ShowOpen
txtFilePath.Text = .filename
End With
End Sub
Private Sub Savepic()
Open "c:\colordraw0094_m.jpg" For Binary Access Read As lngDataFile
lngLengh = LOF(lngDataFile)
If lngLengh = 0 Then Close lngDatafile: Exit Sub
intChunks = lngLengh \ ChunkSize
intFragment = lngLengh Mod ChunkSize
OpenData 打开数据库
Dim i As Int
版权声明:本文由驱动中国整理发布,转载需注明出处与原文链接。如有疑问请联系 editor@qudong.com
本文价值 成为第一个评分的人
登录后为本文打分
网友评论0 条评论
正在回复 的评论取消
评论加载中…
🔐

登录后参与互动

评论、点赞均可赚积分
连续签到、邀请好友也有奖励 🎁

电脑端: 微信扫码登录 微信内: 一键登录

微信扫一扫

打开微信「扫一扫」,分享本文到朋友圈或好友