我目前只学了存储后结果数据添加的方法,我想了解怎样一个字段内一行一行地添加完成记录问题。
还有怎样一个字段内数据输入操作完成后,又让可以其字段的内容后面又反复添加操作呢 如
155
424
846
255
382
491
5
6 这是一个字段内三次添加的结果,14823456添加完成后,又添加524589,又添加546521,需要添加时用这种方法添加。
这个方式怎么做呢
还有怎样一个字段内数据输入操作完成后,又让可以其字段的内容后面又反复添加操作呢 如
155
424
846
255
382
491
5
6 这是一个字段内三次添加的结果,14823456添加完成后,又添加524589,又添加546521,需要添加时用这种方法添加。
这个方式怎么做呢
解决方案 »
- 关于一个R232数据传送代码的修改
- 真TMD恶心,过个生日也上了忽悠!
- dll中变量访问的问题
- 求助: 如何判断一个对象是否为空
- 怎样处理这个问题 Object variable or with block variable not set 急在线等!!!
- 摆脱了,哪里有水晶8.5?非试用的,急用!!!劝告大家一句,如果在98下使用,千万别用水晶9。铭记!!!
- 各位帮帮忙!!我急需一个密码加密的算法!!谢谢!
- 请教98下写的程序在2000下运行问题
- vb类的初始化怎么能完成?
- 标准表达式中数据类型不匹配!!?????请教!!
- 还是有关Datareport的问题
- 用VB6和WINSOCKS能否监听已经使用的端口?
---------------
比如:
update tb set 字段名称=值 where 主键=123
由左到右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 = NothingEnd SubPrivate 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 WithEnd Sub
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 = NothingEnd SubPrivate 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 WithEnd Sub
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 = NothingEnd SubPrivate 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 WithEnd Sub
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 = NothingEnd SubPrivate 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 WithEnd Sub
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 = NothingEnd SubPrivate 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 FunctionPrivate 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 WithEnd Sub