Function CreateDataTable() As DataTable
Dim objConn As New MySql.Data.MySqlClient.MySqlConnection
Dim dtAdapter As MySql.Data.MySqlClient.MySqlDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false"
objConn = New MySql.Data.MySqlClient.MySqlConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM customer"
dtAdapter = New MySql.Data.MySqlClient.MySqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return dt '*** Return DataTable ***'
End Function
Dim dt As DataTable = CreateDataTable()
Dim dr As DataRow
'*** Column ***'
dt.Columns.Add("CustomerID")
dt.Columns.Add("Name")
dt.Columns.Add("Email")
dt.Columns.Add("CountryCode")
dt.Columns.Add("Budget")
dt.Columns.Add("Used")
'*** Rows ***'
dr = dt.NewRow
dr("CustomerID") = "C001"
dr("Name") = "Win Weerachai"
dr("Email") = "[email protected]"
dr("CountryCode") = "TH"
dr("Budget") = "1000000"
dr("Used") = "600000"
dt.Rows.Add(dr)