Hows it going everyone. Im pretty sure theres a simple way to do this, but cant figure it out right now. Im still relatively new to vb .net, and have a function that reads a csv file into a datatable and fills a datagrid. But what I want to do is use this datatable to fill a grid in a different function. So what would be the easiest way to pass a filled datatable to a new function?
Heres the code:
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "All Files..|*.*"
openFileDialog1.Title = "Open File..."
Dim J As Integer = 0
Dim C As Integer = 0
Dim K As Integer = 0
If openFileDialog1.ShowDialog() = DialogResult.OK Then
Dim loadscr As txtload
loadscr = New txtload
loadscr.Show()
Dim wait As Timer
wait = New Timer
wait.Interval = 1000
wait.Start()
wait.Stop()
Try
Dim fs As New IO.FileStream(openFileDialog1.FileName, IO.FileMode.Open)
Dim sr As New IO.StreamReader(fs)
Dim x() As String = sr.ReadLine().Split(CType(",", Char))
Dim NoCol As Integer = x.Length
Dim TxtTable As DataTable
TxtTable = New DataTable
Dim TxtRow As DataRow
'TxtRow = TxtTable.NewRow()
While C < x.Length
TxtTable.Columns.Add(x(C))
filedrop.Items.Add(x(C))
C = C + 1
End While
filedrop.SelectedIndex = 0
Dim r() As String = sr.ReadToEnd().Split(CType(vbCrLf, Char))
Dim colNo As Integer = TxtTable.Columns.Count()
While J < r.Length - 1
Dim col() As String = r(J).Split(CType(",", Char))
TxtRow = TxtTable.NewRow()
K = 0
While K < colNo
TxtRow.Item(K) = col(K)
K = K + 1
End While
TxtTable.Rows.Add(TxtRow)
TxtRow.AcceptChanges()
J = J + 1
End While
Grid1.DataSource = TxtTable
'Table1TableAdapter.Fill(TestdbDataSet.Table1)
loadscr.Close()
MsgBox("Exception File Loaded", MsgBoxStyle.OkOnly = 0, "Exception Loaded")
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End If