1
在这里,我可以从文本文件中检索行和列,并将其存储在名为“tb1”的表中。代码成功运行。现在我想添加一个新的过程,它将从tb1中检索数据,并分别显示textfield1和2和3中的每一行,并添加下一个按钮将显示下一行等等。如何检索存储在数据表中的行和列,并使用visual studio 2010在文本框中显示
Public Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim tbl As New DataTable("mytable")
tbl.Columns.Add("col1", GetType(String))
tbl.Columns.Add("col2", GetType(String))
tbl.Columns.Add("col3", GetType(Integer))
Dim sFilename As String = "C:\test.txt"
Dim myStream As System.IO.StreamReader = New System.IO.StreamReader(sFilename)
Dim line As String
Dim aRow As DataRow
Do
line = myStream.ReadLine()
If line Is Nothing Then
Exit Do
End If
Dim sAry As String() = Split(line, ",") ' separate the fields of the current row
aRow = tbl.NewRow 'get a DataRow that has the required structure
aRow(0) = sAry(0)
aRow(1) = sAry(1)
aRow(2) = sAry(2)
'aRow(2) = CInt(sAry(2))
'MsgBox(aRow(1).ToString)
tbl.Rows.Add(aRow)
Loop
myStream.Close()
For Each aRow In tbl.Rows
Console.WriteLine("{0} {1} {2}", aRow(0), aRow(1), aRow(2))
Next
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Can I access tb1 here?
Also want to try to store this table in sqldatabase...
End Sub