查询数据库所有表所有字段的某个值,生成更新代码 (VB)
2008-11-20 14:25
525 查看
以下是公共模块
Code
VERSION 5.00
Begin VB.Form Form1
Caption = "替换"
ClientHeight = 7680
ClientLeft = 60
ClientTop = 345
ClientWidth = 10650
LinkTopic = "Form1"
ScaleHeight = 7680
ScaleWidth = 10650
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text4
Height = 4575
Left = 120
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 7
Top = 2880
Width = 10455
End
Begin VB.TextBox Text3
Height = 375
Left = 1440
TabIndex = 5
Text = "Provider=SQLOLEDB;Data Source=.\sqlexpress;Initial Catalog=test;User ID=sa;Password=12345678"
Top = 1440
Width = 8535
End
Begin VB.TextBox Text2
Height = 375
Left = 1440
TabIndex = 2
Text = "SZX"
Top = 840
Width = 8535
End
Begin VB.CommandButton Command1
Caption = "开始"
Height = 495
Left = 2760
TabIndex = 1
Top = 2040
Width = 4575
End
Begin VB.TextBox Text1
Height = 375
Left = 1440
TabIndex = 0
Text = "SFT"
Top = 240
Width = 8535
End
Begin VB.Label lblP
AutoSize = -1 'True
Caption = "Cick it"
Height = 180
Left = 7800
TabIndex = 8
Top = 2160
Width = 630
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "数据库:"
Height = 180
Left = 480
TabIndex = 6
Top = 1560
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "替换:"
Height = 180
Index = 1
Left = 480
TabIndex = 4
Top = 960
Width = 450
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "查找:"
Height = 180
Index = 0
Left = 480
TabIndex = 3
Top = 360
Width = 450
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim mystr As String
Dim b As Boolean
Private Sub Command1_Click()
If Command1.Caption = "开始" Then
Command1.Caption = "停止"
StrC = Text3.Text
Text4.Text = ""
Call start
'Command1_Click
Command1.Caption = "开始"
ElseIf Command1.Caption = "停止" Then
Command1.Caption = "开始"
End If
End Sub
Sub start()
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim t As String
Dim f As String
Dim i1 As Long, i2 As Long, i3 As Long, i4 As Long
Set rs = ExecSql("select name from sysobjects where type='U' ", mystr)
If rs.EOF Then Exit Sub
i1 = 0
i2 = 0
i3 = 0
rs.MoveLast
rs.MoveFirst
i4 = rs.RecordCount
SetLab i1, i2, i3, i4
Do While Not rs.EOF
If Command1.Caption = "开始" Then Exit Sub
DoEvents
i3 = i3 + 1
SetLab i1, i2, i3, i4
t = "[" & rs.Fields(0) & "]"
't = t & Space(40 - Len(t))
Set rs1 = ExecSql("Select Name from SysColumns Where id=Object_Id('" & t & "') and xtype in ( select xtype from systypes where name in ( 'varchar ', 'nvarchar', 'char', 'nchar') )", mystr)
If Not rs1.EOF Then
rs1.MoveLast
rs1.MoveFirst
i2 = rs1.RecordCount
Do While Not rs1.EOF
DoEvents
i1 = i1 + 1
SetLab i1, i2, i3, i4
f = "[" & rs1.Fields(0) & "]"
If Val(GetName(" select count(1) from " & t & " where " & f & " = '" & Text1.Text & "'")) > 0 Then
Text4.Text = Text4.Text & " update " & t & Space(40 - Len(t)) & " set " & f & Space(30 - Len(f)) & "='" & Text2.Text & "' where " & f & Space(30 - Len(f)) & " = '" & Text1.Text & "'" & vbCrLf
End If
rs1.MoveNext
Loop
End If
i1 = 0
rs.MoveNext
Loop
End Sub
Sub SetLab(i1 As Long, i2 As Long, i3 As Long, i4 As Long)
lblP.Caption = "Current:" & i1 & "/" & i2 & vbCrLf & "Total:" & i3 & "/" & i4
Text4.SelStart = Len(Text4.Text)
End Sub
Code
VERSION 5.00
Begin VB.Form Form1
Caption = "替换"
ClientHeight = 7680
ClientLeft = 60
ClientTop = 345
ClientWidth = 10650
LinkTopic = "Form1"
ScaleHeight = 7680
ScaleWidth = 10650
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text4
Height = 4575
Left = 120
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 7
Top = 2880
Width = 10455
End
Begin VB.TextBox Text3
Height = 375
Left = 1440
TabIndex = 5
Text = "Provider=SQLOLEDB;Data Source=.\sqlexpress;Initial Catalog=test;User ID=sa;Password=12345678"
Top = 1440
Width = 8535
End
Begin VB.TextBox Text2
Height = 375
Left = 1440
TabIndex = 2
Text = "SZX"
Top = 840
Width = 8535
End
Begin VB.CommandButton Command1
Caption = "开始"
Height = 495
Left = 2760
TabIndex = 1
Top = 2040
Width = 4575
End
Begin VB.TextBox Text1
Height = 375
Left = 1440
TabIndex = 0
Text = "SFT"
Top = 240
Width = 8535
End
Begin VB.Label lblP
AutoSize = -1 'True
Caption = "Cick it"
Height = 180
Left = 7800
TabIndex = 8
Top = 2160
Width = 630
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "数据库:"
Height = 180
Left = 480
TabIndex = 6
Top = 1560
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "替换:"
Height = 180
Index = 1
Left = 480
TabIndex = 4
Top = 960
Width = 450
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "查找:"
Height = 180
Index = 0
Left = 480
TabIndex = 3
Top = 360
Width = 450
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim mystr As String
Dim b As Boolean
Private Sub Command1_Click()
If Command1.Caption = "开始" Then
Command1.Caption = "停止"
StrC = Text3.Text
Text4.Text = ""
Call start
'Command1_Click
Command1.Caption = "开始"
ElseIf Command1.Caption = "停止" Then
Command1.Caption = "开始"
End If
End Sub
Sub start()
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim t As String
Dim f As String
Dim i1 As Long, i2 As Long, i3 As Long, i4 As Long
Set rs = ExecSql("select name from sysobjects where type='U' ", mystr)
If rs.EOF Then Exit Sub
i1 = 0
i2 = 0
i3 = 0
rs.MoveLast
rs.MoveFirst
i4 = rs.RecordCount
SetLab i1, i2, i3, i4
Do While Not rs.EOF
If Command1.Caption = "开始" Then Exit Sub
DoEvents
i3 = i3 + 1
SetLab i1, i2, i3, i4
t = "[" & rs.Fields(0) & "]"
't = t & Space(40 - Len(t))
Set rs1 = ExecSql("Select Name from SysColumns Where id=Object_Id('" & t & "') and xtype in ( select xtype from systypes where name in ( 'varchar ', 'nvarchar', 'char', 'nchar') )", mystr)
If Not rs1.EOF Then
rs1.MoveLast
rs1.MoveFirst
i2 = rs1.RecordCount
Do While Not rs1.EOF
DoEvents
i1 = i1 + 1
SetLab i1, i2, i3, i4
f = "[" & rs1.Fields(0) & "]"
If Val(GetName(" select count(1) from " & t & " where " & f & " = '" & Text1.Text & "'")) > 0 Then
Text4.Text = Text4.Text & " update " & t & Space(40 - Len(t)) & " set " & f & Space(30 - Len(f)) & "='" & Text2.Text & "' where " & f & Space(30 - Len(f)) & " = '" & Text1.Text & "'" & vbCrLf
End If
rs1.MoveNext
Loop
End If
i1 = 0
rs.MoveNext
Loop
End Sub
Sub SetLab(i1 As Long, i2 As Long, i3 As Long, i4 As Long)
lblP.Caption = "Current:" & i1 & "/" & i2 & vbCrLf & "Total:" & i3 & "/" & i4
Text4.SelStart = Len(Text4.Text)
End Sub
相关文章推荐
- 查询当前数据库中所有有默认值的字段,并生成添加默认值的SQL语句
- 最近设计了一个生成asp代码的程序,同时也可以作为数据库管理查询的软件,有兴趣的朋友可以去下载!
- 查询数据库所有字段
- 生成/读取(反向更新数据库) Excel文件(示例代码下载)
- php将数据库中所有内容生成静态html文档的代码
- sql语句查询 sql server access 数据库里的所有表名,字段名
- SQLSERVER查询所有数据库名,表名,和字段名
- Oracle 查询数据库中包含某一特定值的所有字段名,以及表名
- 查询所有数据库中的所有表的所有字段的信息
- sql 查询所有数据库、表名、表字段总结
- SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int
- 查询数据库的所有表,字段
- 查询sqlserver中所有的数据库表 and 查询表中的说明注释字段
- sql 查询所有数据库、表名、表字段总结
- sql server 查询所有数据库,一个数据库中所有表和表的所有字段
- Mysql中查询某个数据库中所有表的字段信息
- 查询数据库中表中所有的字段名
- Mysql中查询某个数据库中所有表的字段信息
- sql语句查询Oracle|sql server|access 数据库里的所有表名,字段名
- 查询数据库所有表中包含的字段