How to select an excel data Table using a drop downlist value - vb.net

I am working on an application that uses excel files as its data source. I would love the DataGridView to populate with the columns of a sheet when a worksheet name is selected from the drop down list.
Here is what I have tried doing:
Imports System.Data.OleDb
Public Class Form101
Public cn As New OleDbConnection
Public cm As New OleDbCommand
Public da As OleDbDataAdapter
Dim comb As String
Public dt As New DataTable
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Comb1.SelectedIndexChanged
comb = Comb1.SelectedText
End Sub
Public Sub FillDataGridView(ByVal Query As String)
da = New OleDbDataAdapter(Query, cn)
dt.Clear()
da.Fill(dt)
With DataGridView1
.DataSource = dt
.Columns(0).HeaderText = "Date"
.Columns(1).HeaderText = "Qty brought"
.Columns(2).HeaderText = "Qty sold"
.Columns(3).HeaderText = "Goods balance"
.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
End With
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\toojah app\Stock card.xls; Extended Properties= Excel 8.0;"
cn.Open()
FillDataGridView("select * FROM ['" & comb & "'] ")
End Sub
End Class

Try something like this. The first function will collect all of the columns and records in your excel file and place it into a datatable. Then If you wanted to add additional columns to the datable you can do it in the Public Sub CreateDataGridView. This has been tested and works.
Friend Shared Function BuildDatatable () as datatable
Dim dt As New DataTable
Dim Conn As System.Data.OleDb.OleDbConnection
Dim cmd As System.Data.OleDb.OleDbDataAdapter
dim MyFile as string = "C:\toojah app\Stock card.xls"
Conn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + MyFile + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1';")
Conn.Open()
Dim dtSheets As DataTable = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Dim listSheet As New List(Of String)
Dim drSheet As DataRow
For Each drSheet In dtSheets.Rows
listSheet.Add(drSheet("TABLE_NAME").ToString())
cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [" & drSheet("TABLE_NAME").ToString() & "]", Conn)
cmd.TableMappings.Add("Table", "Net-informations.com")
cmd.Fill(dt)
Conn.Close()
Next
Return dt
Catch ex As Exception
Return Nothing
End Try
End Function
'This is used to pass the function datatable as a dt to then pass to the public sub as shown below.
Dim dt As DataTable = BuildDatatable
Public Sub CreateDataGridView(dt)
Dim newColumn As New Data.DataColumn("ComeColumnName", GetType(System.String))
newColumn.DefaultValue = "YourValues"
dt.Columns.Add(newColumn)
DataGridView1.DataSource = dt
End Sub

Related

Combobox population does not appear in DataGridView in vb.net

Combobox population does not appear in DataGridView because of the function of DataTable.
below link the previous code running normally with the combobox population.
please recommend the best solution.
I have also coded in my post so it doesn't miss communication
Thanks
link previous post
Private _dt As DataTable
'update code PopulateComboBox in form load
Public Sub New()
If Me.IsInDesignMode() Then
Return
End If
InitializeComponent()
Me.PopulateComboBox()
fillDataGridView1()
End Sub
Private Function GetAndFillDataTable() As DataTable
Dim dt As New DataTable()
Dim query As String = "SELECT NOD,ITM,CIA,DPR,QTY FROM RSD WHERE QTY > 0 AND PNM=#PNM"
Using con As OleDbConnection = New OleDbConnection(GetConnectionString)
Using cmd As OleDbCommand = New OleDbCommand(query, con)
cmd.Parameters.AddWithValue("#PNM", ComboBox1.SelectedValue)
Using da As New OleDbDataAdapter(cmd)
da.Fill(dt)
da.Dispose()
Dim totalColumn As New DataColumn()
totalColumn.DataType = System.Type.GetType("System.Double")
totalColumn.ColumnName = "Total"
totalColumn.Expression = "[CIA]*[QTY]*(1-[DPR]/100)"
dt.Columns.Add(totalColumn)
Return dt
End Using
End Using
End Using
End Function
Private Sub FillDataGridView1()
If (_dt Is Nothing) Then
_dt = GetAndFillDataTable()
End If
grid.DataSource = _dt
grid.Refresh()
End Sub
Private Sub PopulateComboBox()
Dim dt As New DataTable()
Dim query As String = "SELECT DISTINCT PNM FROM RSD UNION SELECT DISTINCT PNM FROM RSG ORDER BY PNM"
Try
dt = New DataTable
Using con As OleDbConnection = New OleDbConnection(GetConnectionString)
Using sda As OleDbDataAdapter = New OleDbDataAdapter(query, con)
sda.Fill(dt)
Dim row As DataRow = dt.NewRow()
row(0) = ""
dt.Rows.InsertAt(row, 0)
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "PNM"
ComboBox1.ValueMember = "PNM"
End Using
End Using
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
End Try
'update code combobox selectionchangecommited for fillDataGridView1
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
fillDataGridView1()
End Sub
You are setting your datasource = _dt in PopulateComboBox however the data table you built in your function is called dt.

Binding a Data Set/Table to a DataGridView

I am currently writing a simple stock control Visual Basic program linked to a database.
Here's what it looks like so far.
The form displays the data in a DataGrid View and I am trying to refresh my DataGridView automatically when data is changed (using SQL) in the database I am using.
After doing some research I have found that the best way to do this is by binding the data table (using BindingSource) to the DataGridView
However I am struggling to implement this, as every implementation I have tried results in a blank DataGridView and would thoroughly appreciate it if someone could assist me.
Here's the code:
Imports System.Data.OleDb
Public Class Form1
Public connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dbStock.accdb"
Public conn As New OleDb.OleDbConnection(connectionString)
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TblStockControlTableAdapter.Fill(Me.DbStockDataSet.tblStockControl)
For i As Integer = 1 To 5
ComboBoxQty1.Items.Add(i)
ComboBoxQty2.Items.Add(i)
Next
Dim SqlQuery As String = "Select tblStockControl.[EggType] FROM tblStockControl"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlQuery, conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "tblStockControl")
Dim dt As DataTable = ds.Tables("tblStockControl")
'DataGridView1.DataSource = dt
For Each row As DataRow In dt.Rows
ComboBoxAdd.Items.Add(row.Item(0))
Next
For Each row As DataRow In dt.Rows
ComboBoxTake.Items.Add(row.Item(0))
Next
End Sub
Private Sub btnAddEgg_Click(sender As Object, e As EventArgs) Handles btnAddEgg.Click
conn.Open()
Dim SqlQuery As String = "Select tblStockControl.[Quantity] FROM tblStockControl WHERE EggType = '" & ComboBoxAdd.Text & "'"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlQuery, conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "tblStockControl")
Dim dt As DataTable = ds.Tables("tblStockControl")
Dim qty As Integer = 0
For Each row As DataRow In dt.Rows
For Each column As DataColumn In dt.Columns
qty = row(column)
Next
Next
Dim NewQty As Integer = qty + CInt(ComboBoxQty2.Text)
UpdateAddQty(NewQty)
conn.Close()
End Sub
Function UpdateAddQty(ByRef NewQty As Integer) As Integer
Dim SqlUpdate As String = "UPDATE tblStockControl SET Quantity = '" & NewQty & "' WHERE EggType = '" & ComboBoxAdd.Text & "'"
Dim SqlCommand As New OleDbCommand
With SqlCommand
.CommandText = SqlUpdate
.Connection = conn
.ExecuteNonQuery()
End With
Return (Nothing)
End Function
Private Sub btnViewStock_Click(sender As Object, e As EventArgs) Handles btnViewStock.Click
'Add code to open Access file.
End Sub
Private Sub btnTakeEgg_Click(sender As Object, e As EventArgs) Handles btnTakeEgg.Click
conn.Open()
Dim SqlQuery As String = "Select tblStockControl.[Quantity] FROM tblStockControl WHERE EggType = '" & ComboBoxTake.Text & "'"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlQuery, conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "tblStockControl")
Dim dt As DataTable = ds.Tables("tblStockControl")
Dim qty As Integer = 0
For Each row As DataRow In dt.Rows
For Each column As DataColumn In dt.Columns
qty = row(column)
Next
Next
Dim NewQty As Integer = CInt(ComboBoxQty1.Text) - qty
UpdateTakeQty(NewQty)
conn.Close()
End Sub
Function UpdateTakeQty(ByRef NewQty As Integer) As Integer
Dim SqlUpdate As String = "UPDATE tblStockControl SET Quantity = '" & NewQty & "' WHERE EggType = '" & ComboBoxTake.Text & "'"
Dim SqlCommand As New OleDbCommand
With SqlCommand
.CommandText = SqlUpdate
.Connection = conn
.ExecuteNonQuery()
End With
Return (Nothing)
End Function
End Class
If you are using a DataTable , then reset the dataasource of the DataGridView.I mean you need to read data from the database again. :
'Do this every time you add/Update a data
Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlQuery, conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "tblStockControl")
Dim dt As DataTable = ds.Tables("tblStockControl")
Or you can just create a row for every data you add to your database :
'Do this every time you add a data
DataGridViewRow row = (DataGridViewRow)DataGridView1.Rows[0].Clone()
row.Cells[0].Value = "Alex"
row.Cells[1].Value = "Jordan"
DataGridView1.Rows.Add(row)

Display Excel values in DataGridView

I am having an issue with filling a DataGridView from an Excel file that is online. On button click, the app should create a new tab, add a DataGridView and populate with values from the Excel file. How can I do it?
Here is what I did so far:
Public Class Form1
Dim tempTabExist = False
Private Sub SiteList_Click(sender As Object, e As EventArgs) Handles SiteList.Click
Dim xlApp As Excel.Application
Dim wkbTemplRaspored As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
If tempTabExist = False Then
Call CreateNewTabPage()
End If
xlApp = New Excel.Application
xlApp.Visible = True
wkbTemplRaspored = xlApp.Workbooks.Open("http://CRNO/RAN/Raspored%20R%20A%20N_v1.xlsx")
xlWorkSheet = wkbTemplRaspored.Worksheets("Sheet1")
End Sub
Private Sub CreateNewTabPage()
Dim tp As New TabPage
tempTabExist = True
tp.Name = "SiteList"
tp.Text = "SiteList"
Call CreateNewGrid(tp)
Me.TabControl.TabPages.Add(tp)
End Sub
Private Sub CreateNewGrid(ByRef TP As TabPage)
Dim dg As New DataGridView
dg.Dock = DockStyle.Fill
dg.Name = "Raspored"
dg.Columns.Add(dg.Name, "Site Name")
dg.Columns.Add(dg.Name, "Technology")
dg.Columns.Add(dg.Name, "Week")
dg.Columns.Add(dg.Name, "Engineer")
TP.Controls.Add(dg)
End Sub
End Class
Most of your code seems to be working. I would change a few things however apart from listing the data in your DataGridView the code does appear to work.
To retrieve data from Excel and view in a DataGridView I would look at the following code:
Using con As New Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Test.xlsx'; Extended Properties='Excel 12.0;';"),
com As Data.OleDb.OleDbCommand = con.CreateCommand()
con.Open()
Dim dtSheetName As DataTable
dtSheetName = con.GetSchema("Tables")
If dtSheetName.Rows.Count > 0 Then
com.CommandText = "select * from [" & dtSheetName.Rows(0)("TABLE_NAME").ToString() & "]"
com.CommandType = CommandType.Text
dtRows.Load(com.ExecuteReader())
End If
End Using
There are bits of code here you may need to change as I haven't tested with your Data Source. Instead I used my own.
I would look at changing your method CreateNewTabPage slightly to return a TabPage:
Private Function CreateNewTabPage() As TabPage
Dim tp As New TabPage
tp.Name = "SiteList"
tp.Text = "SiteList"
Return tp
End Function
Instead of calling CreateNewGrid from CreateNewTabPage I would do this on your button click. I would however pass through the DataTable as well as the TabPage.
Additionally since we are assigning a DataTable as the DataSource we don't need to add columns manually. Here is what I would do:
Private Sub CreateNewGrid(ByRef TP As TabPage,
ByVal dt As DataTable)
Dim dg As New DataGridView
dg.Dock = DockStyle.Fill
dg.Name = "Raspored"
dg.DataSource = dt
TP.Controls.Add(dg)
End Sub
This is how I would call both methods:
If dtRows.Rows.Count > 0 Then
Dim tabPage As TabPage = CreateNewTabPage()
If tabPage IsNot Nothing Then
If TabControl1.TabPages.ContainsKey(tabPage.Name) Then
TabControl1.TabPages.RemoveByKey(tabPage.Name)
End If
CreateNewGrid(tabPage, dtRows)
TabControl1.TabPages.Add(tabPage)
End If
End If
Notice that I check for the tab and should it exist, I remove it. You may want to do something similar.
All together your code would look something like this:
Private Sub SiteList_Click(sender As Object, e As EventArgs) Handles SiteList.Click
Dim dtRows As New DataTable
Using con As New Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='http://CRNO/RAN/Raspored%20R%20A%20N_v1.xlsx'; Extended Properties='Excel 12.0;';"),
com As Data.OleDb.OleDbCommand = con.CreateCommand()
con.Open()
Dim dtSheetName As DataTable
dtSheetName = con.GetSchema("Tables")
If dtSheetName.Rows.Count > 0 Then
com.CommandText = "select * from [" & dtSheetName.Rows(0)("TABLE_NAME").ToString() & "]"
com.CommandType = CommandType.Text
dtRows.Load(com.ExecuteReader())
End If
End Using
If dtRows.Rows.Count > 0 Then
Dim tabPage As TabPage = CreateNewTabPage()
If tabPage IsNot Nothing Then
If TabControl1.TabPages.ContainsKey(tabPage.Name) Then
TabControl1.TabPages.RemoveByKey(tabPage.Name)
End If
CreateNewGrid(tabPage, dtRows)
TabControl1.TabPages.Add(tabPage)
End If
End If
End Sub
Private Function CreateNewTabPage() As TabPage
Dim tp As New TabPage
tp.Name = "SiteList"
tp.Text = "SiteList"
Return tp
End Function
Private Sub CreateNewGrid(ByRef TP As TabPage,
ByVal dt As DataTable)
Dim dg As New DataGridView
dg.Dock = DockStyle.Fill
dg.Name = "Raspored"
dg.DataSource = dt
TP.Controls.Add(dg)
End Sub
If you haven't already you may need to download Microsoft Access Database Engine 2010 Redistributable.
There are several ways to do this. Here are two ideas for you to muse over.
Imports System.Data.SqlClient
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Users\Excel\Desktop\Book1.xls';Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Net-informations.com")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
End Sub
End Class
Also, try this.
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Data.OleDb
'~~> Define your Excel Objects
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim xlApp As New Excel.Application
'Dim xlWorkBook As Excel.Workbook
'Dim xlWorkSheet As Excel.Worksheet
Dim strConn As String
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim dao_dbE As dao.DBEngine
Dim dao_DB As DAO.Database
Dim strFirstSheetName As String
dao_dbE = New dao.DBEngine
dao_DB = dao_dbE.OpenDatabase("C:\Users\Excel\Desktop\Coding\DOT.NET\Samples VB\Import into DataGrid from Excel & Export from DataGrid to Excel #2\Book3.xls", False, True, "Excel 8.0;")
strFirstSheetName = dao_DB.TableDefs(0).Name
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\Excel\Desktop\Coding\DOT.NET\Samples VB\Import into DataGrid from Excel & Export from DataGrid to Excel #2\Book3.xls;Extended Properties=""Excel 8.0;"""
da = New OleDbDataAdapter("SELECT * FROM [" & _
strFirstSheetName & "]", strConn)
da.TableMappings.Add("Table", "Excel")
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0).DefaultView
da.Dispose()
dao_DB.Close()
End Sub
End Class

Populating Textbox and DropdownLists

I am having a hard time trying to populate a textbox, and two dropdown lists. What I am attempting to do is this: when the Company dropdownlist has been selected, it will display a grid of its respective values from a sqldatasource, which it does. Now the next step is once a selection from the company dropdown has been made, a textbox will display the membertype as well as the second dropdownlist. The third dropdown displays the groupid. All these three components have their outputs after a selection has been made. But I cannot seem to get the values to show. I also added code for clarification.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.UI.WebControls
Partial Class companydropdown
Inherits System.Web.UI.Page
Private Sub BindDropDownList(DropdownList1 As DropDownList, query As String, text As String, value As String, defaultText As String)
If Not IsPostBack Then
' Read sql server connection string from web.config file
Dim sConstr As String = ConfigurationManager.ConnectionStrings("ds17701ConnectionString").ConnectionString
Dim Conn As New SqlConnection(sConstr)
Dim dt As New DataTable("tbl")
Using Conn
Conn.Open()
Dim comm As New SqlCommand("SELECT CompanyName,CompanyID FROM CompanyList ORDER BY CompanyName", Conn)
Dim da As New SqlDataAdapter(comm)
'da.Fill(dt)
End Using
'DropdownList1.DataSource = dt
DropdownList1.DataTextField = "CompanyName"
DropdownList1.DataValueField = "CompanyID"
DropdownList1.DataBind()
'DropdownList1.Items.Insert(0, New ListItem("--Select--"))
End If
End Sub
Protected Sub Member_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If DropDownList1.SelectedIndex > 0 Then
Dim sConstr As String = ConfigurationManager.ConnectionStrings("ds17701ConnectionString").ConnectionString
Dim Conn As New SqlConnection(sConstr)
Dim dt As New DataTable("tbl")
Using Conn
Conn.Open()
Dim comm As New SqlCommand("SELECT CompanyName,CompanyID FROM CompanyList " + DropDownList1.SelectedValue & " ORDER BY CompanyName", Conn)
Dim da As New SqlDataAdapter(comm)
da.Fill(dt)
End Using
'DropDownList2.DataSource = dt
DropDownList2.DataTextField = "MembershipStatus"
DropDownList2.DataValueField = "MemberTypeID"
' Bind sql server data into the Dropdown List
DropDownList2.DataBind()
Else
DropDownList2.Items.Clear()
End If
End Sub
Protected Sub Group_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If DropDownList1.SelectedIndex > 0 Then
Dim sConstr As String = ConfigurationManager.ConnectionStrings("ds17701ConnectionString").ConnectionString
Dim Conn As New SqlConnection(sConstr)
Dim dt As New DataTable("tbl")
Using Conn
Conn.Open()
Dim comm As New SqlCommand("SELECT CompanyName,CompanyID FROM CompanyList " + DropDownList1.SelectedValue & " ORDER BY CompanyName", Conn)
Dim da As New SqlDataAdapter(comm)
da.Fill(dt)
End Using
'DropDownList2.DataSource = dt
DropDownList3.DataTextField = "GroupID"
DropDownList3.DataValueField = "GroupID"
' Bind sql server data into the Dropdown List
DropDownList3.DataBind()
Else
DropDownList3.Items.Clear()
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
DropDownList2.Enabled = False
'DropDownList3.Items.Clear()
DropDownList3.Items.Insert(0, New ListItem("", "0"))
Dim stateId As Integer = Integer.Parse(DropDownList1.SelectedItem.Value)
If stateId > 0 Then
Dim query As String = String.Format("", stateId)
BindDropDownList(DropDownList1, query, "CompanyName", "CompanyId", "")
DropDownList3.Enabled = True
DropDownList2.Enabled = True
End If
End Sub
End Class

how to use recordset movelast

i need help for the code that i can use old rs.movelast to vb.net 2010..
any simple way to query my record that automatic select the last..
here is my connection sample i just call it only in any form..///
Public Function ExecuteSQLQuery(ByVal SQLQuery As String) As DataTable
Try
Dim sqlCon As New OleDbConnection(CnString)
Dim sqlDA As New OleDbDataAdapter(SQLQuery, sqlCon)
Dim sqlCB As New OleDbCommandBuilder(sqlDA)
sqlDT.Reset() ' refresh
sqlDA.Fill(sqlDT)
Catch ex As Exception
MsgBox("Error : " & ex.Message)
End Try
Return sqlDT
End Function
sqlDT.rows(sqlDT.rows.count-1) will be the last record of your DataTable sqlDT. sqlDT.rows.count-1 will return you the last index of the rows in the filled table. Hope it will help you. Thanks
Imports System.Data.OleDb
Public Class Form1
Public CnString As String = "Provider=SQLOLEDB;Data Source=HP-PC\SQLEXPRESS;Persist Security Info=True;Password=sa;User ID=sa;Initial Catalog=Accounts"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ssql As String = "Select * from TBL_Access"
Dim dt As DataTable
dt = ExecuteSQLQuery(ssql)
TextBox1.Text = dt.Rows(dt.Rows.Count - 1)(0) 'Value of First Column of Last Row of DataTable dt
TextBox2.Text = dt.Rows(dt.Rows.Count - 1)(1) 'Value of Second Column of Last Row of DataTable dt
End Sub
Public Function ExecuteSQLQuery(ByVal SQLQuery As String) As DataTable
Try
Dim sqlCon As New OleDbConnection(CnString)
Dim sqlDA As New OleDbDataAdapter(SQLQuery, sqlCon)
Dim sqlCB As New OleDbCommandBuilder(sqlDA)
Dim sqlDT As New DataTable
sqlDT.Reset() ' refresh
sqlDA.Fill(sqlDT)
Return sqlDT
Catch ex As Exception
MsgBox("Error : " & ex.Message)
Return Nothing
End Try
End Function
End Class