| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 490 人关注过本帖
标题:[求助]如何用VB制作批量替换工具?
只看楼主 加入收藏
圣域无敌
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2007-3-26
收藏
 问题点数:0 回复次数:2 
[求助]如何用VB制作批量替换工具?
由于我工作需要,要将一定量的ACCESS数据库表里的NULL内容替换为空,我现在的做法是打开数据库表,用ACCESS里的替换工具替换,一两个数据库还可以,但是量一多就麻烦了!

要求:能够把指定数据库的表内所有NULL替换为空!
能够把指定一定数量的数据库的表里的NULL替换为空!


我想到的方法是在表里查找NULL,然后UPDATA空值,但是循环结束条件不知道如何写,大虾教下吧!这样做只能一个字段一个字段的找,ACC里面是一条记录一条记录的找,这个又要如何做呢?
另外,如果我想一次性操作一定数量的数据库?
搜索更多相关主题的帖子: 批量 工具 制作 
2007-05-10 20:47
圣域无敌
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2007-3-26
收藏
得分:0 

没人会吗?

2007-05-11 22:30
圣域无敌
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2007-3-26
收藏
得分:0 

Option Explicit
Public DBCON As New ADODB.Connection
Public RsChange As New ADODB.Recordset
Public RsCount As New ADODB.Recordset


'----------------------------------------------------------------------------------------

Private Sub CountNum() '//获取记录数

DBCON.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\" & txtDBName.Text & ".mdb;Persist Security Info=False"
DBCON.Open

If RsCount.State = adStateClosed Then '//打开记录集
RsCount.Open "" & txtDBName.Text & "", DBCON, adOpenKeyset, adLockPessimistic, adCmdTable
End If

Dim count1 As Integer
count1 = RsCount.RecordCount
RsCount.Close
txtCount.Text = count1
DBCON.Close
End Sub
Private Sub DBopen()

DBCON.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\" & txtDBName.Text & ".mdb;Persist Security Info=False"
DBCON.Open

End Sub


'----------------------------------------------------------------------------------------

Public Function e1() '//phone
Dim i As Integer
Dim num As Integer
num = txtCount.Text
For i = 1 To num
Call Change
Next
End Function
Public Function e2() '//remark

Dim i As Integer
Dim num As Integer
num = txtCount.Text
For i = 1 To num
Call Change2
Next
End Function
Public Function e3() '//name
Dim i As Integer
Dim num As Integer
num = txtCount.Text
For i = 1 To num
Call Change3
Next
End Function
Public Function e4() '//address
Dim i As Integer
Dim num As Integer
num = txtCount.Text
For i = 1 To num
Call Change4
Next
End Function


'----------------------------------------------------------------------------------------

Private Sub cmdChange_Click()
Call CountNum
Call DBopen
Call e1
DBCON.Close
Call DBopen
Call e2
DBCON.Close
Call DBopen
Call e3
DBCON.Close
Call DBopen
Call e4
DBCON.Close

MsgBox "OK!"
End Sub

'----------------------------------------------------------------------------------------

Public Function Change() '//phone
On Error GoTo over
Dim StrSQL As String
StrSQL = "select * from " & txtDBName.Text & " where phone= '" & txtFind.Text & "'"

If RsChange.State = adStateClosed Then
RsChange.Open StrSQL, DBCON, adOpenDynamic, adLockOptimistic, adCmdText
End If

RsChange!phone = Empty
RsChange.Update
RsChange.MoveNext

over:
If Err.Number = 3021 Then
End If

End Function

Public Function Change2() '//remark
On Error GoTo over

Dim StrSQL As String
StrSQL = "select * from " & txtDBName.Text & " where remark= '" & txtFind.Text & "'"

If RsChange.State = adStateClosed Then
RsChange.Open StrSQL, DBCON, adOpenDynamic, adLockOptimistic, adCmdText
End If

RsChange!remark = Empty
RsChange.Update
RsChange.MoveNext
over:
If Err.Number = 3021 Then
End If

End Function

Public Function Change3() '//name
On Error GoTo over

Dim StrSQL As String
StrSQL = "select * from " & txtDBName.Text & " where name= '" & txtFind.Text & "'"

If RsChange.State = adStateClosed Then
RsChange.Open StrSQL, DBCON, adOpenDynamic, adLockOptimistic, adCmdText
End If

RsChange!Name = Empty
RsChange.Update

RsChange.MoveNext
over:
If Err.Number = 3021 Then
End If

End Function

Public Function Change4() '//address
On Error GoTo over

Dim StrSQL As String
StrSQL = "select * from " & txtDBName.Text & " where address= '" & txtFind.Text & "'"

If RsChange.State = adStateClosed Then
RsChange.Open StrSQL, DBCON, adOpenDynamic, adLockOptimistic, adCmdText
End If

RsChange!address = Empty
RsChange.Update
RsChange.MoveNext
over:
If Err.Number = 3021 Then
End If

End Function

我做的,不要笑啊,谁能教我更好的方法?

2007-05-11 22:36
快速回复:[求助]如何用VB制作批量替换工具?
数据加载中...
 
   



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

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