| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2344 人关注过本帖
标题:[求助]在vb定义ADODB.Recordset出错???
只看楼主 加入收藏
xke3636
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-5-30
收藏
 问题点数:0 回复次数:6 
[求助]在vb定义ADODB.Recordset出错???

XVoXNQGg.rar (4.07 KB) [求助]在vb定义ADODB.Recordset出错???


Option Explicit
Dim rs_tude As New ADODB.Recordset
Dim gridclick As Boolean
Dim select_row As String '记录选择的土地
Dim getrow As Long

Private Sub cmdadd_Click()
On Error GoTo adderror
If cmdadd.Caption = "保存" Then
cmdadd.Caption = "增加"
If Trim(txttudezhengbianhao.Text) = "" Then
MsgBox "土地证编号不能为空!", vbOKOnly + vbExclamation, "出错啦!"
txttudezhengbianhao.SetFocus
Exit Sub
End If
If Trim(txttudemianji.Text) = "" Then
MsgBox "土地面积不能为空!", vbOKOnly + vbExclamation, "出错啦!"
txttudemianji.SetFocus
Exit Sub
End If
If Trim(txtzongjia.Text) = "" Then
MsgBox "总价不能为空!", vbOKOnly + vbExclamation, "出错啦!"
txtzongjia.SetFocus
Exit Sub
End If
If Trim(Combo1.Text) = "" Then
MsgBox "请选择是否已出售!", vbOKOnly + vbExclamation, "出错啦!"
Combo1.SetFocus
Exit Sub
End If
rs_tude.MoveFirst
Dim i As Integer
For i = 0 To rs_tude.RecordCount - 1
If rs_tude.Fields(0) = txttudezhengbianhao.Text Then
MsgBox "土地证编号重复!", vbOKOnly + vbExclamation, "出错啦!"
txttudezhengbianhao.SetFocus
Exit Sub
End If
rs_tude.MoveNext
Next i
rs_tude.MoveLast
rs_tude.AddNew
rs_tude.Fields(0) = txtPct_id.Text
rs_tude.Fields(1) = txttudezhengbianhao.Text
rs_tude.Fields(2) = txtfangchanzhengbianhao.Text
rs_tude.Fields(3) = Combo1.Text
If Trim(txttudemianji.Text) = "" Then '土地面积信息
rs_tude.Fields(4) = Null
Else
rs_tude.Fields(4) = txttudemianji.Text
End If
If Trim(txtweizhi.Text) = "" Then '位置信息
rs_tude.Fields(5) = Null
Else
rs_tude.Fields(5) = txtweizhi.Text
End If
If Trim(txtsuoyouquanren.Text) = "" Then '所有权人信息
rs_tude.Fields(6) = Null
Else
rs_tude.Fields(6) = txtsuoyouquanren.Text
End If
If Trim(txtzhanyongdanwei.Text) = "" Then '占用单位信息
rs_tude.Fields(7) = Null
Else
rs_tude.Fields(7) = txtzhanyongdanwei.Text
End If
If Trim(txtzongjia.Text) = "" Then '总价信息
rs_tude.Fields(8) = Null
Else
rs_tude.Fields(8) = txtzongjia.Text
End If
If Trim(txtmaijia.Text) = "" Then '买家信息
rs_tude.Fields(9) = Null
Else
rs_tude.Fields(9) = txtmaijia.Text
End If
If Trim(txtbeizhu.Text) = "" Then '备注信息
rs_tude.Fields(10) = Null
Else
rs_tude.Fields(10) = txtbeizhu.Text
End If
rs_tude.Update
MsgBox "添加成功!", vbOKOnly + vbExclamation, "OK"
With gridtude
.Rows = rs_tude.RecordCount + 1
.Row = gridtude.Rows - 1
.Col = 0
.Text = txtPct_id.Text
.Col = 1
.Text = txttudezhengbianhao.Text
.Col = 2
.Text = txtfangchanzhengbianhao.Text
.Col = 3
.Text = txttudemianji.Text
.Col = 4
.Text = txtweizhi.Text
.Col = 5
.Text = txtsuoyouquanren.Text
.Col = 6
.Text = txtzhanyongdanwei.Text
.Col = 7
.Text = txtzongjia.Text
.Col = 8
.Text = Combo1.Text
.Col = 9
.Text = txtmaijia.Text
.Col = 10
.Text = txtbeizhu.Text
End With
Else
cmdadd.Caption = "保存"
txtPct_id.Text = ""
txttudezhengbianhao.Text = ""
txtfangchanzhengbianhao.Text = ""
txttudemianji.Text = ""
txtweizhi.Text = ""
txtsuoyouquanren.Text = ""
txtzhanyongdanwei.Text = ""
txtzongjia.Text = ""
txtmaijia.Text = ""
txtbeizhu.Text = ""
cmdmodify.Enabled = False
cmddel.Enabled = False
End If
Exit Sub
adderror:
MsgBox Err.Description
End Sub

Private Sub cmdmodify_Click()
On Error GoTo modifyerror
txtPct_id.Enabled = False
If Trim(txttudezhengbianhao.Text) = "" Then
MsgBox "土地证编号不能为空!", vbOKOnly + vbExclamation, "出错啦!"
txttudezhengbianhao.SetFocus
Exit Sub
End If
rs_tude.MoveFirst
Dim i As Integer
For i = 0 To rs_tude.RecordCount - 1
If rs_tude.Fields(0) = txtPct_id.Text Then
rs_tude.Fields(1) = txttudezhengbianhao.Text
rs_tude.Fields(2) = txtfangchanzhengbianhao.Text
rs_tude.Fields(3) = Combo1.Text
If Trim(txttudemianji.Text) = "" Then '土地面积信息
rs_tude.Fields(4) = Null
Else
rs_tude.Fields(4) = txttudemianji.Text
End If
If Trim(txtweizhi.Text) = "" Then '位置信息
rs_tude.Fields(5) = Null
Else
rs_tude.Fields(5) = txtweizhi.Text
End If
If Trim(txtsuoyouquanren.Text) = "" Then '所有权人信息
rs_tude.Fields(6) = Null
Else
rs_tude.Fields(6) = txtsuoyouquanren.Text
End If
If Trim(txtzhanyongdanwei.Text) = "" Then '占用单位信息
rs_tude.Fields(7) = Null
Else
rs_tude.Fields(7) = txtzhanyongdanwei.Text
End If
If Trim(txtzongjia.Text) = "" Then '总价信息
rs_tude.Fields(8) = Null
Else
rs_tude.Fields(8) = txtzongjia.Text
End If
If Trim(txtmaijia.Text) = "" Then '买家信息
rs_tude.Fields(9) = Null
Else
rs_tude.Fields(9) = txtmaijia.Text
End If
If Trim(txtbeizhu.Text) = "" Then '备注信息
rs_tude.Fields(10) = Null
Else
rs_tude.Fields(10) = txtbeizhu.Text
End If
rs_tude.Update
MsgBox "修改成功!", vbOKOnly + vbExclamation, "OK"
With gridtude
.Row = getrow
.Col = 0
.Text = txtPct_id.Text
.Col = 1
.Text = txttudezhengbianhao.Text
.Col = 2
.Text = txtfangchanzhengbianhao.Text
.Col = 3
.Text = txttudemianji.Text
.Col = 4
.Text = txtweizhi.Text
.Col = 5
.Text = txtsuoyouquanren.Text
.Col = 6
.Text = txtzhanyongdanwei.Text
.Col = 7
.Text = txtzongjia.Text
.Col = 8
.Text = Combo1.Text
.Col = 9
.Text = txtmaijia.Text
.Col = 10
.Text = txtbeizhu.Text
End With
Exit Sub
End If
rs_tude.MoveNext
Next i
modifyerror:
MsgBox Err.Description
End Sub

Private Sub cmddel_Click()
Dim answer As String
Dim delete_row As String
On Error GoTo delerror
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then
rs_tude.MoveFirst
Dim i As Integer
For i = 0 To rs_tude.RecordCount - 1
If rs_tude.Fields(0) = txttudezhengbianhao.Text Then
rs_tude.Delete
rs_tude.Update
MsgBox "删除成功!", vbOKOnly + vbExclamation, "OK"
With gridtude
.RemoveItem getrow
End With
Exit Sub
End If
rs_tude.MoveNext
Next i
Else
Exit Sub
End If
Exit Sub
delerror:
MsgBox Err.Description
End Sub

Private Sub cmdexit_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim sql As String
On Error GoTo loaderror
sql = "select * from 土地"
rs_tude.CursorLocation = adUseClient
rs_tude.Open sql, conn, adOpenKeyset, adLockPessimistic
setgrid
setgridhead
displaygrid
Combo1.AddItem "已售"
Combo1.AddItem "未售"
Combo1.AddItem "预付中"
cmdmodify.Enabled = False
cmddel.Enabled = False
gridclick = False
Exit Sub
loaderror:
MsgBox Err.Description
End Sub

Public Sub displaygrid()
Dim i As Integer
Dim j As Integer
On Error GoTo displayerror
gridtude.Row = 0
If Not rs_tude.EOF Then
rs_tude.MoveFirst
Do While Not rs_tude.EOF
gridtude.Row = gridtude.Row + 1
For j = 0 To 11
gridtude.Col = j
If Not IsNull(rs_tude.Fields(j)) Then gridtude.Text = _
rs_tude.Fields(j) Else gridtude.Text = ""
Next j
rs_tude.MoveNext
Loop
End If
displayerror:
If Err.Number <> 0 Then
MsgBox Err.Description
End If
End Sub

Public Sub setgrid()
Dim i As Integer
On Error GoTo seterror
With gridtude
.ScrollBars = flexScrollBarBoth
.FixedCols = 1
.Rows = rs_tude.RecordCount + 1
.Cols = 10
.SelectionMode = flexSelectionByRow
For i = 0 To .Rows - 1
.RowHeight(i) = 315
Next
For i = 0 To .Cols - 1
.ColWidth(i) = 1500
Next i
End With
Exit Sub
seterror:
MsgBox Err.Description
End Sub

Public Sub setgridhead()
On Error GoTo setheaderror
gridtude.Row = 0
gridtude.Col = 0
gridtude.Text = "合同编号"
gridtude.Col = 1
gridtude.Text = "土地证编号"
gridtude.Col = 2
gridtude.Text = "房产证编号"
gridtude.Col = 3
gridtude.Text = "土地面积"
gridtude.Col = 4
gridtude.Text = "位置"
gridtude.Col = 5
gridtude.Text = "所有权人"
gridtude.Col = 6
gridtude.Text = "占用单位"
gridtude.Col = 7
gridtude.Text = "总价"
gridtude.Col = 8
gridtude.Text = "是否已出售"
gridtude.Col = 9
gridtude.Text = "买家"
gridtude.Col = 10
gridtude.Text = "备注"
Exit Sub
setheaderror:
MsgBox Err.Description
End Sub

Private Sub Form_Unload(Cancel As Integer)
rs_tude.Close
End Sub

Private Sub gridtude_Click()
On Error GoTo griderror
gridclick = True
cmdmodify.Enabled = True
cmddel.Enabled = True
getrow = gridtude.Row
If gridtude.Rows = 1 Then
MsgBox "无相关纪录", vbOKOnly + vbExclamation, ""
Else
select_row = gridtude.TextMatrix(getrow, 0)
displaymingxi
End If
griderror:
If Err.Number <> 0 Then
MsgBox Err.Description
End If
End Sub

Public Sub displaymingxi()
txttudezhengbianhao.Text = select_row
txtPct_id.Text = gridtude.TextMatrix(getrow, 0)
txtfangchanzhengbianhao.Text = gridtude.TextMatrix(getrow, 2)
txttudemianji.Text = gridtude.TextMatrix(getrow, 4)
txtweizhi.Text = gridtude.TextMatrix(getrow, 5)
txtsuoyouquanren.Text = gridtude.TextMatrix(getrow, 6)
txtzhanyongdanwei.Text = gridtude.TextMatrix(getrow, 7)
txtzongjia.Text = gridtude.TextMatrix(getrow, 8)
txtmaijia.Text = gridtude.TextMatrix(getrow, 9)
txtbeizhu.Text = gridtude.TextMatrix(getrow, 10)
Combo1.Text = gridtude.TextMatrix(getrow, 3)
End Sub

本人在编译这个窗体时经常报错,光标落在Dim rs_tude As New ADODB.Recordset上,报错为未定义变量,有谁可以告诉怎样解决??

搜索更多相关主题的帖子: Recordset ADODB quot 定义 Dim 
2006-05-30 13:46
maui2000
Rank: 1
等 级:新手上路
威 望:1
帖 子:113
专家分:0
注 册:2006-5-23
收藏
得分:0 
引用了部件没??
2006-05-30 14:01
xke3636
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-5-30
收藏
得分:0 
[求助]

怎么引用啊??请详细指教

2006-05-31 00:49
llingma
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2006-5-19
收藏
得分:0 
在工程菜单里添加对ADO的引用

2006-05-31 16:35
xke3636
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-5-30
收藏
得分:0 
可以说说详细的工程吗???
2006-06-01 23:45
bx138222040
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-4-17
收藏
得分:0 

你没有引用ADO控件怎么能作呢!!!在部件里引用ADO控件就可以了

2006-06-23 09:53
maui2000
Rank: 1
等 级:新手上路
威 望:1
帖 子:113
专家分:0
注 册:2006-5-23
收藏
得分:0 
估计又是一个拿来主义者`~`
2006-06-23 10:15
快速回复:[求助]在vb定义ADODB.Recordset出错???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032107 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved