Sub save_in_array(ByVal rs As Data.DataTable, ByVal arr(,) As String, ByVal col As Integer)
Dim n As Integer
Dim j As Integer
Dim i As Integer
n = row_number(rs) ‘ 用来求数据库中有数据的行数,这里的n返回值是3
ReDim arr(n - 1, col - 1)
For i = 0 To n - 1
For j = 0 To col - 1
arr(i, j) = rs.Rows(i)(j)
Next
Next
End Sub
``` 定义了一个过程,作用是将数据表格中的数存到数组里,
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim j As Integer
Dim n As Integer
Dim i As Integer
Dim place As String
Dim length As Integer
Call save_in_array(DataSet11.Tables("s_run"), arr_s_run, 4)
If OpenFileDialog1.FileName <> "" Then
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
FileOpen(2, My.Application.Info.DirectoryPath & "\swapmid.key", OpenMode.Output)
Do While Not EOF(1)
a = LineInput(1)
PrintLine(2, a)
Debug.Print(a)
Loop
FileClose(1, 2)
place = OpenFileDialog1.FileName
Kill(OpenFileDialog1.FileName)
FileOpen(1, My.Application.Info.DirectoryPath & "\swapmid.key", OpenMode.Input)
FileOpen(2, place, OpenMode.Output)
Do While Not EOF(1)
a = LineInput(1)
If InStr(1, a, "IRGFIL") <> 0 And InStr(1, a, "CALFIL") <> 0 Then
PrintLine(2, a)
n = row_number(DataSet11.Tables("s_run"))
Debug.Print(n)
For i = 0 To n - 1
For j = 0 To 4
length = Len(arr_s_run(i, j))
Select Case j
Case 4
If length < 5 Then arr_s_run(i, j) = New String("", 5 - length) & arr_s_run(i, j)
Case Else
If length < 8 Then arr_s_run(i, j) = New String("", 8 - length) & arr_s_run(i, j)
End Select
a = " " & "'" & arr_s_run(i, j) & "'"
Next
PrintLine(2, a)
Next
Do
a = LineInput(1)
Loop Until InStr(1, a, "*") <> 0
End If
Loop
End If
FileClose(1, 2)
End Sub

这是还没有调用文件前的界面

这是要打开的文件,点button1,将txt文件上的'huinong1' ' YEAR07' ' huinong' ' huinon1' ' rs0'查找出来放在数据库里,显示在界面上

点击button2之后,将修改的数据保存在数据和txt文件里,在txt文件里格式要和之前一样,应该是这一步出错了,希望哪位帮我看看,不胜感激