| | |
Passing a DataTable VB .NET 08
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2007
Posts: 45
Reputation:
Solved Threads: 1
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:
Heres the code:
VB Syntax (Toggle Plain Text)
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
•
•
Join Date: Jul 2008
Posts: 23
Reputation:
Solved Threads: 2
you can pass a datatable just like any other class (string, integer, object, etc). What do you mean by another function?
Adam Snider
Construction Accounting Software
Construction Accounting Software
•
•
Join Date: Jul 2008
Posts: 23
Reputation:
Solved Threads: 2
Yeah, you would declare it as a form level variable....for instance:
Hope that helps! Good luck!
VB.NET Syntax (Toggle Plain Text)
Public Class Form1 Private dtTable1 as Datatable Private Sub LoadDataTable dtTable = new DataTable dtTable = FillDataTableCode End Sub Private Sub ButtonClick grd1.datasource = dtTable end Sub End Class
Hope that helps! Good luck!
Adam Snider
Construction Accounting Software
Construction Accounting Software
![]() |
Similar Threads
- Passing Parameters to Linked Subreports (VB.NET)
- IListSource does not contain any data sources (ASP.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Insert data for mobile 5.0(vs 2008)
- Next Thread: Saving Drawn Bitmaps
| Thread Tools | Search this Thread |
"crystal .net .net2005 2008 access add advanced application array assignment basic beginner box button buttons center click client code combo convert cpu data database datagrid datagridview designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall forms html image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web winsock wpf wrapingcode xml





