求助vb 数据库添加问题

txlk33 2008-11-10 11:14:50
我目前只学了存储后结果数据添加的方法,我想了解怎样一个字段内一行一行地添加完成记录问题。
还有怎样一个字段内数据输入操作完成后,又让可以其字段的内容后面又反复添加操作呢


155
424
846
255
382
491
5
6 这是一个字段内三次添加的结果,14823456添加完成后,又添加524589,又添加546521,需要添加时用这种方法添加。
这个方式怎么做呢
...全文
87 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jhone99 2008-11-11
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim intCount As Integer
Dim intEndRow As Integer
Dim intStart As Integer

cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mydb.mdb;Persist Security Info=False"

rs.Open "select * from mytable", cn, adOpenStatic, adLockOptimistic


If rs.RecordCount > 0 Then
While Not rs.EOF
For i = rs.Fields.Count - 1 To 0 Step -1
If Len(rs.Fields(1)) > intCount Then
intCount = Len(rs.Fields(1))
End If
Next i
rs.MoveNext
Wend

rs.MoveFirst
End If

' intCount = intCount + 1

With MSFlexGrid1
.Col = Text2.Text 'Text2指定要填入的列

For i = .Rows - 1 To 1 Step -1
.Row = i

If Trim(.Text) <> "" Then
intEndRow = i
Exit For
End If
Next i

If intEndRow > 0 Then
intStart = fun_get_location(Text2.Text)

If intStart > 0 Then
For m = intStart To intEndRow
.Row = m
If rs.EOF Then
rs.AddNew
rs.Fields(0) = m - i
rs.Fields(1) = Space(intCount) & .Text
rs.Update
Else
rs.Fields(1) = rs.Fields(1) & Space(intCount - Len(rs.Fields(1))) & .Text
rs.Update
End If

rs.MoveNext
Next m
End If
End If
End With


rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing

End Sub

Private Function fun_get_location(ByVal intCol As Integer) As Integer
Dim i As Integer

For i = 1 To MSFlexGrid1.Rows - 1
Data = Data & MSFlexGrid1.TextMatrix(i, intCol)
Next i

If InStr(1, Data, Text1.Text) > 0 Then
fun_get_location = InStr(1, Data, Text1.Text) + Len(Text1.Text)
Else
fun_get_location = 0
End If


End Function

Private Sub Form_Load()
Dim TextLine
Dim strFileName As String
Dim a() As String
Dim i As Integer
Dim j As Integer


With MSFlexGrid1
.Rows = 20
.Cols = 6

strFileName = App.Path & "\testdata2.txt"

Open strFileName For Input As #1 ' 打开文件。

Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
i = i + 1
.Row = i
For j = 1 To Len(TextLine)
.Col = j
.Text = Mid(TextLine, j, 1)
Next j

Loop

Close #1 ' 关闭文件。
End With

End Sub
jhone99 2008-11-11
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim intCount As Integer
Dim intEndRow As Integer

cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mydb.mdb;Persist Security Info=False"

rs.Open "select * from mytable", cn, adOpenStatic, adLockOptimistic


If rs.RecordCount > 0 Then
While Not rs.EOF
For i = rs.Fields.Count - 1 To 0 Step -1
If Len(rs.Fields(1)) > intCount Then
intCount = Len(rs.Fields(1))
End If
Next i
rs.MoveNext
Wend

rs.MoveFirst
End If

' intCount = intCount + 1

With MSFlexGrid1
.Col = Text2.Text 'Text2指定要填入的列

For i = .Rows - 1 To 1 Step -1
.Row = i

If Trim(.Text) <> "" Then
intEndRow = i
Exit For
End If
Next i

If intEndRow > 0 Then
For i = 1 To intEndRow
.Row = i

If .Text = Text1.Text Then
For m = i + 1 To intEndRow
.Row = m
If rs.EOF Then
rs.AddNew
rs.Fields(0) = m - i
rs.Fields(1) = Space(intCount) & .Text
rs.Update
Else
rs.Fields(1) = rs.Fields(1) & Space(intCount - Len(rs.Fields(1))) & .Text
rs.Update
End If

rs.MoveNext
Next m
End If
Next i
End If
End With


rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing

End Sub

Private Sub Form_Load()
Dim TextLine
Dim strFileName As String
Dim a() As String
Dim i As Integer
Dim j As Integer


With MSFlexGrid1
.Rows = 20
.Cols = 6

strFileName = App.Path & "\testdata2.txt"

Open strFileName For Input As #1 ' 打开文件。

Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
i = i + 1
.Row = i
For j = 1 To Len(TextLine)
.Col = j
.Text = Mid(TextLine, j, 1)
Next j

Loop

Close #1 ' 关闭文件。
End With

End Sub
jhone99 2008-11-11
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim intCount As Integer
Dim intEndRow As Integer

cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mydb.mdb;Persist Security Info=False"

rs.Open "select * from mytable", cn, adOpenStatic, adLockOptimistic


If rs.RecordCount > 0 Then
While Not rs.EOF
For i = rs.Fields.Count - 1 To 0 Step -1
If Len(rs.Fields(1)) > intCount Then
intCount = Len(rs.Fields(1))
End If
Next i
rs.MoveNext
Wend

rs.MoveFirst
End If

' intCount = intCount + 1

With MSFlexGrid1
.Col = Text2.Text 'Text2指定要填入的列

For i = .Rows - 1 To 1 Step -1
.Row = i

If Trim(.Text) <> "" Then
intEndRow = i
Exit For
End If
Next i

If intEndRow > 0 Then
For i = 1 To intEndRow
.Row = i

If rs.EOF Then
rs.AddNew
rs.Fields(0) = i
rs.Fields(1) = Space(intCount) & .Text
rs.Update
Else
rs.Fields(1) = rs.Fields(1) & Space(intCount - Len(rs.Fields(1))) & .Text
rs.Update
End If

rs.MoveNext
Next i
End If
End With


rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing

End Sub

Private Sub Form_Load()
Dim TextLine
Dim strFileName As String
Dim a() As String
Dim i As Integer
Dim j As Integer


With MSFlexGrid1
.Rows = 20
.Cols = 6

strFileName = App.Path & "\testdata2.txt"

Open strFileName For Input As #1 ' 打开文件。

Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
i = i + 1
.Row = i
For j = 1 To Len(TextLine)
.Col = j
.Text = Mid(TextLine, j, 1)
Next j

Loop

Close #1 ' 关闭文件。
End With

End Sub
jhone99 2008-11-11
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim intCount As Integer
Dim intEndRow As Integer

cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mydb.mdb;Persist Security Info=False"

rs.Open "select * from mytable", cn, adOpenStatic, adLockOptimistic


If rs.RecordCount > 0 Then
While Not rs.EOF
For i = rs.Fields.Count - 1 To 0 Step -1
If Len(rs.Fields(1)) > intCount Then
intCount = Len(rs.Fields(1))
End If
Next i
rs.MoveNext
Wend

rs.MoveFirst
End If

' intCount = intCount + 1

With MSFlexGrid1
.Col = Text2.Text 'Text2指定要填入的列

For i = .Rows - 1 To 1 Step -1
.Row = i

If Trim(.Text) <> "" Then
intEndRow = i
Exit For
End If
Next i

If intEndRow > 0 Then
For i = 1 To intEndRow
.Row = i

If rs.EOF Then
rs.AddNew
rs.Fields(0) = i
rs.Fields(1) = .Text
rs.Update
Else
rs.Fields(1) = rs.Fields(1) & Space(intCount - Len(rs.Fields(1))) & .Text
rs.Update
End If

rs.MoveNext
Next i
End If
End With


rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing

End Sub

Private Sub Form_Load()
Dim TextLine
Dim strFileName As String
Dim a() As String
Dim i As Integer
Dim j As Integer


With MSFlexGrid1
.Rows = 20
.Cols = 6

strFileName = App.Path & "\testdata2.txt"

Open strFileName For Input As #1 ' 打开文件。

Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
i = i + 1
.Row = i
For j = 1 To Len(TextLine)
.Col = j
.Text = Mid(TextLine, j, 1)
Next j

Loop

Close #1 ' 关闭文件。
End With

End Sub
「已注销」 2008-11-10
  • 打赏
  • 举报
回复
描述不清
txlk33 2008-11-10
  • 打赏
  • 举报
回复
具体点
vbman2003 2008-11-10
  • 打赏
  • 举报
回复
还有怎样一个字段内数据输入操作完成后,又让可以其字段的内容后面又反复添加操作呢
---------------
比如:
update tb set 字段名称=值 where 主键=123
jhone99 2008-11-10
  • 打赏
  • 举报
回复
text1 指定一列填入一列
由左到右

Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim intCount As Integer
Dim intEndRow As Integer

cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mydb.mdb;Persist Security Info=False"

rs.Open "select * from mytable", cn, adOpenStatic, adLockOptimistic


If rs.RecordCount > 0 Then
While Not rs.EOF
For i = rs.Fields.Count - 1 To 0 Step -1
If rs.Fields(i) <> Null Or rs.Fields(i) <> "" Then
If i > intCount Then
intCount = i
End If
Exit For
End If
Next i
rs.MoveNext
Wend

rs.MoveFirst
End If

intCount = intCount + 1

With MSFlexGrid1
.Col = Text1.Text 'Text2指定要填入的列

For i = .Rows - 1 To 1 Step -1
.Row = i

If Trim(.Text) <> "" Then
intEndRow = i
Exit For
End If
Next i

If intEndRow > 0 Then
For i = 1 To intEndRow
.Row = i

If rs.EOF Then
rs.AddNew
rs.Fields(0) = i
rs.Fields(intCount) = .Text
rs.Update
Else
rs.Fields(intCount) = .Text
rs.Update
End If

rs.MoveNext
Next i
End If
End With


rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing

End Sub

Private Sub Form_Load()
Dim TextLine
Dim strFileName As String
Dim a() As String
Dim i As Integer
Dim j As Integer


With MSFlexGrid1
.Rows = 20
.Cols = 6

strFileName = App.Path & "\testdata2.txt"

Open strFileName For Input As #1 ' 打开文件。

Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
i = i + 1
.Row = i
For j = 1 To Len(TextLine)
.Col = j
.Text = Mid(TextLine, j, 1)
Next j

Loop

Close #1 ' 关闭文件。
End With

End Sub

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧