蓝色情调大哥我要接着问,其他朋友也来帮忙看看吧!

bluesanke 2003-04-03 10:39:43
Option Explicit

Dim Mycn As new adodb.connection'数据库连接对象,用于打开数据库
Dim Myrs1 As new adodb.Recordset'记录集对象,用于存入记录的
Dim Myrs2 As new adodb.Recordset'记录集对象,用于存入记录的

Private Sub Command1_Click()
Dim cnstring as string'用于存放连接字符串的
cnsstring="Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & "\data\XXXX.mdb;" _
& "Persist Security Info=False"
'连接字符串,这相要根据你自己的实际情况来改一下。
mycn.open cnstring
mycn.CursorLocation=adUseClient
If Option1.Value = True Then
If Text1.Text = "" Then
MsgBox "请正确填写进库单号码!", vbOKOnly + vbExclamation, "信息提示"
Text1.SetFocus
Exit Sub
Else
Myrs1.open "select * from inlib where 进库单号码='" & Trim(Text1) & "'",mycn
MSFlexGrid1.Clear
TableInit
If Myrs1.RecordCount >= 1 Then
Myrs2.open "select * from inlibdetail,goods where 进库单号码='" & Trim(Text1) & "' And GoodsID = 材料编码",mycn
While Myrs2.EOF = False
MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
MSFlexGrid1.Row = MSFlexGrid1.Rows - 1
MSFlexGrid1.Col = 0
MSFlexGrid1.Text = Myrs1.Fields("进库单号码")
MSFlexGrid1.Col = 1
MSFlexGrid1.Text = Myrs1.Fields("发票号码")
MSFlexGrid1.Col = 2
MSFlexGrid1.Text = Myrs1.Fields("进库日期")
MSFlexGrid1.Col = 3
If IsNull(Myrs1.Fields("经办人")) Then
MSFlexGrid1.Text = ""
Else
MSFlexGrid1.Text = Myrs1.Fields("经办人")
End If
MSFlexGrid1.Col = 4
If IsNull(Myrs1.Fields("保管人")) Then
MSFlexGrid1.Text = ""
Else
MSFlexGrid1.Text = Myrs1.Fields("保管人")
End If
MSFlexGrid1.Col = 5
MSFlexGrid1.Text = Myrs2.Fields("goodsid")
MSFlexGrid1.Col = 6
MSFlexGrid1.Text = Myrs2.Fields("goodsname")
MSFlexGrid1.Col = 7
MSFlexGrid1.Text = Myrs2.Fields("type")
MSFlexGrid1.Col = 8
MSFlexGrid1.Text = Myrs2.Fields("unit")
MSFlexGrid1.Col = 9
MSFlexGrid1.Text = Myrs2.Fields("数量")
MSFlexGrid1.Col = 10
MSFlexGrid1.Text = Format(Myrs2.Fields("单价"), "#0.00")
MSFlexGrid1.Col = 11
MSFlexGrid1.Text = Format(Myrs2.Fields("金额"), "#0.00")
MSFlexGrid1.Col = 12
If IsNull(Myrs2.Fields("备注")) Then
MSFlexGrid1.Text = ""
Else
MSFlexGrid1.Text = Myrs2.Fields("备注")
End If
Myrs2.MoveNext
Wend
Myrs2.Close
Else
MsgBox "不存在这个进库单号码", vbOKOnly + vbExclamation, "信息提示"
Text1 = ""
Text1.SetFocus
Exit Sub
End If
Myrs1.Close
End If
End If
end sub
很明显Myrs2是从多个表里读取数据,现在我只要从一个表里读就行,怎么修改上面的代码呀!就是取掉和Myrs2有关的代码!另外运行到mycn.open cnstring这句老说实施错误“3701”运行到MSFlexGrid1.Col = 1
MSFlexGrid1.Text = Myrs1.Fields("发票号码")总说实施错误“94”无效使用“null“
...全文
7 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
IwantFlay 2003-04-03
MsFlexGRid1.text=trim(Myrs1.fields("发票号码") & " ")

只是因为取出的值是一个NULL,不做处理是不能用的.
回复
饮水需思源 2003-04-03
MSFlexGrid1.Text = Myrs1.Fields("发票号码") & ""
回复
chenyu5188 2003-04-03
在你新贴的代码上修改了:
Option Explicit
Dim Mycn As ADODB.Connection '数据库连接对象,用于打开数据库
Dim Myrs1 As ADODB.Recordset '记录集对象,用于存入记录的
Dim cnstring As String '用于存放连接字符串的
Private Sub Command1_Click()
Set Mycn=New ADODB.Connection
Set Myrs1=New ADODB.Recordset
cnstring = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=dytd;PassWord=dytd;Data Source=dytd"
Mycn.Open cnstring
Mycn.CursorLocation = adUseClient
If Option1.Value = True Then
If Text1.Text = "" Then
MsgBox "请正确填写申请书编号!", vbOKOnly + vbExclamation, "信息提示"
Text1.SetFocus
Exit Sub
Else
Myrs1.Open "select * from DJ_CSDJ_TDDJSQS where DCT_BH='" & Trim(Text1) & "'", Mycn
if myrs1.bof and myrs1.eof then
MsgBox "不存在申请书编号!!!", vbOKOnly + vbExclamation, "信息提示"
Text1 = ""
Text1.SetFocus
Myrs1.close
set myrs1=Nothing
Exit Sub
end if
MSHFlexGrid1.Clear
TableInit
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
MSHFlexGrid1.Row = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Col = 0
................................
................................
................................
MSHFlexGrid1.Text = Myrs1.Fields("DCT_TH") & ""
MSHFlexGrid1.Col = 42
MSHFlexGrid1.Text = Myrs1.Fields("DCT_DH") & ""
End If
Myrs1.close
set myrs1=Nothing
Else
Mycn.clsoe'关闭连接对象
Set mycn=nothing
Myrs1.close'关闭记录集对象
Set myrs1=Nothing
Exit Sub
End If
End Sub

以上修改你再再结合你的程序仔细看看,有可能不符你程序的地方,你可以在上面修改。
还有问题的话发短信给我。
回复
chenyu5188 2003-04-03
因为你第一次使用的记录没有关闭,你要在程序结束时加一个关闭记录集的语句。
回复
chenyu5188 2003-04-03
Oracle 数据库我没有用过。
连接Oracle数据库的连接字符串:
OLE DB Provider for Oracle (from Microsoft) :
oConn.Open "Provider=msdaora;" & _
"Data Source=MyOracleDB;" & _ '你程序中的数据源,数据库名
"User Id=myUsername;" & _ '用户名
"Password=myPassword" '密码

OLE DB Provider for Oracle (from Oracle) :
oConn.Open "Provider=OraOLEDB.Oracle;" & _
"Data Source=MyOracleDB;" & _
"User Id=myUsername;" & _
"Password=myPassword"

以上给出了一个来自Oracle 和来自Microsoft的连接字符串。

机子有要有Oracle数据库的驱动引擎才可以正常连接。
回复
bluesanke 2003-04-03
Option Explicit
Dim Mycn As New ADODB.Connection '数据库连接对象,用于打开数据库
Dim Myrs1 As New ADODB.Recordset '记录集对象,用于存入记录的
Dim Myrs2 As New ADODB.Recordset '记录集对象,用于存入记录的





Private Sub Command1_Click()
Dim cnstring As String '用于存放连接字符串的
cnstring = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=dytd;PassWord=dytd;Data Source=dytd"
Mycn.Open cnstring
Mycn.CursorLocation = adUseClient
If Option1.Value = True Then
If Text1.Text = "" Then
MsgBox "请正确填写申请书编号!", vbOKOnly + vbExclamation, "信息提示"
Text1.SetFocus
Exit Sub
Else
Myrs1.Open "select * from DJ_CSDJ_TDDJSQS where DCT_BH='" & Trim(Text1) & "'", Mycn
MSHFlexGrid1.Clear
TableInit
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
MSHFlexGrid1.Row = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Col = 0
MSHFlexGrid1.Text = Myrs1.Fields("DCT_BH") & ""
MSHFlexGrid1.Col = 1
MSHFlexGrid1.Text = Myrs1.Fields("DCT_TDSYZ") & ""
MSHFlexGrid1.Col = 2
MSHFlexGrid1.Text = Myrs1.Fields("DCT_DZ") & ""
MSHFlexGrid1.Col = 3
MSHFlexGrid1.Text = Myrs1.Fields("DCT_RQ") & ""
MSHFlexGrid1.Col = 4
MSHFlexGrid1.Text = Myrs1.Fields("DCT_TEL") & ""
MSHFlexGrid1.Col = 5
MSHFlexGrid1.Text = Myrs1.Fields("DCT_FRDBXM") & ""
MSHFlexGrid1.Col = 6
MSHFlexGrid1.Text = Myrs1.Fields("DCT_ZGBM") & ""
MSHFlexGrid1.Col = 7
MSHFlexGrid1.Text = Myrs1.Fields("DCT_DWXZ") & ""
MSHFlexGrid1.Col = 8
MSHFlexGrid1.Text = Myrs1.Fields("DCT_SYQX") & ""
MSHFlexGrid1.Col = 9
MSHFlexGrid1.Text = Myrs1.Fields("DCT_QSXZ") & ""
MSHFlexGrid1.Col = 10
MSHFlexGrid1.Text = Myrs1.Fields("DCT_ZZRQ") & ""
MSHFlexGrid1.Col = 11
MSHFlexGrid1.Text = Myrs1.Fields("DCT_TDZL") & ""
MSHFlexGrid1.Col = 12
MSHFlexGrid1.Text = Myrs1.Fields("DCT_SYQLX") & ""
MSHFlexGrid1.Col = 13
MSHFlexGrid1.Text = Myrs1.Fields("DCT_HD") & ""
MSHFlexGrid1.Col = 14
MSHFlexGrid1.Text = Myrs1.Fields("DCT_ST") & ""
MSHFlexGrid1.Col = 15
MSHFlexGrid1.Text = Myrs1.Fields("DCT_YD") & ""
MSHFlexGrid1.Col = 16
MSHFlexGrid1.Text = Myrs1.Fields("DCT_LD") & ""
MSHFlexGrid1.Col = 17
MSHFlexGrid1.Text = Myrs1.Fields("DCT_MCD") & ""
MSHFlexGrid1.Col = 18
MSHFlexGrid1.Text = Myrs1.Fields("DCT_ZJD") & ""
MSHFlexGrid1.Col = 19
MSHFlexGrid1.Text = Myrs1.Fields("DCT_QYYD") & ""
MSHFlexGrid1.Col = 20
MSHFlexGrid1.Text = Myrs1.Fields("DCT_JTYD") & ""
MSHFlexGrid1.Col = 21
MSHFlexGrid1.Text = Myrs1.Fields("DCT_SY") & ""
MSHFlexGrid1.Col = 22
MSHFlexGrid1.Text = Myrs1.Fields("DCT_WLYTD") & ""
MSHFlexGrid1.Col = 23
MSHFlexGrid1.Text = Myrs1.Fields("DCT_DZMJ") & ""
MSHFlexGrid1.Col = 24
MSHFlexGrid1.Text = Myrs1.Fields("DCT_DZTDYT") & ""
MSHFlexGrid1.Col = 25
MSHFlexGrid1.Text = Myrs1.Fields("DCT_DZJSYD") & ""
MSHFlexGrid1.Col = 26
MSHFlexGrid1.Text = Myrs1.Fields("DCT_DZTDDJ") & ""
MSHFlexGrid1.Col = 27
MSHFlexGrid1.Text = Myrs1.Fields("DCT_GYMJ") & ""
MSHFlexGrid1.Col = 28
MSHFlexGrid1.Text = Myrs1.Fields("DCT_GYJZWLX") & ""
MSHFlexGrid1.Col = 29
MSHFlexGrid1.Text = Myrs1.Fields("DCT_GYFTMJ") & ""
MSHFlexGrid1.Col = 30
MSHFlexGrid1.Text = Myrs1.Fields("DCT_GYFTJZZD") & ""
MSHFlexGrid1.Col = 31
MSHFlexGrid1.Text = Myrs1.Fields("DCT_GYDSWQS") & ""
MSHFlexGrid1.Col = 32
MSHFlexGrid1.Text = Myrs1.Fields("DCT_GYSBDJ") & ""
MSHFlexGrid1.Col = 33
MSHFlexGrid1.Text = Myrs1.Fields("DCT_TXQL") & ""
MSHFlexGrid1.Col = 34
MSHFlexGrid1.Text = Myrs1.Fields("DCT_SQDJYJ") & ""
MSHFlexGrid1.Col = 35
MSHFlexGrid1.Text = Myrs1.Fields("DCT_FT") & ""
MSHFlexGrid1.Col = 36
MSHFlexGrid1.Text = Myrs1.Fields("DCT_D") & ""
MSHFlexGrid1.Col = 37
MSHFlexGrid1.Text = Myrs1.Fields("DCT_N") & ""
MSHFlexGrid1.Col = 38
MSHFlexGrid1.Text = Myrs1.Fields("DCT_X") & ""
MSHFlexGrid1.Col = 39
MSHFlexGrid1.Text = Myrs1.Fields("DCT_B") & ""
MSHFlexGrid1.Col = 40
MSHFlexGrid1.Text = Myrs1.Fields("DCT_BZ") & ""
MSHFlexGrid1.Col = 41
MSHFlexGrid1.Text = Myrs1.Fields("DCT_TH") & ""
MSHFlexGrid1.Col = 42
MSHFlexGrid1.Text = Myrs1.Fields("DCT_DH") & ""
MsgBox "不存在这个进库单号码", vbOKOnly + vbExclamation, "信息提示"
Text1 = ""
Text1.SetFocus
End If
Exit Sub
End If
这是我现在正用的代码,可是只能查一遍,第2次就说实施错误,‘3705’对象打开时操作不被允许!
回复
chenyu5188 2003-04-03
楼主的连接正确吗???有没有根据你自己的程序所需更改?!
回复
bluesanke 2003-04-03
用楼上的这位朋友的,不能运行,说数据已关闭
回复
cbr7619 2003-04-03
mycn.ConnectionString=cnstring
回复
bluesanke 2003-04-03
上面的问题解决了,剩下的2个问题呢?
很明显Myrs2是从多个表里读取数据,现在我只要从一个表里读就行,怎么修改上面的代码呀!就是取掉和Myrs2有关的代码!另外运行到mycn.open cnstring这句老说实施错误“3701”运行到MSFlexGrid1.Col = 1
回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2003-04-03 10:39
社区公告
暂无公告