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