Hi,
I am just starting to learn VB.NET and would very much appreciate a little help. I went through several books - got the Wizard version of db connections, datagrid, binding context, etc. I prefer the programmatic version of knowledge. Programmatically I set up the db connection, estab the data adapter and data set. Access is the db with only one table for now. All I want to do is update a record-call the record NAME. The following is the coding I have done to establish the connection, data adapter, data set, data table, etc.
I just want to have a button that I can have the working code to update the database via the dataset. Any help is appreciated.
Thanks,
John
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Dim conn AsNew OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\people.mdb;User Id=;Password=;")
Dim da AsNew OleDb.OleDbDataAdapter
Dim ds AsNew DataSet
Dim sqlQuery AsString
sqlQuery = "Select * from [Names]"
da.SelectCommand = New OleDb.OleDbCommand(sqlQuery, conn)
'If I want to populate a datatable object outside of the DS object
'I can Dim a datatable and set it equal to the particular table (called "Names")
'which I added to the dataset (done on the right side of the equation)
'Supposedly, specifying the datatable name in the fill method of the dataset object
'will create and load the datatable so I don't have to explicitly use an "Add"
'method as I have done below.
Dim Names As DataTable = ds.Tables.Add("Names")
da.Fill(ds, "Names")
Dim dRow As DataRow
Dim dCol As DataColumn
ForEach Names In ds.Tables
ForEach dRow In Names.Rows
ForEach dCol In Names.Columns
Console.WriteLine(dRow(dCol))
fName.Items.Add(dRow(dCol))
Next
Next
Next
fName.Text = dRow(dCol)
fName.Text = dRow.ItemArray(1)
EndSub
EndClass
I am just starting to learn VB.NET and would very much appreciate a little help. I went through several books - got the Wizard version of db connections, datagrid, binding context, etc. I prefer the programmatic version of knowledge. Programmatically I set up the db connection, estab the data adapter and data set. Access is the db with only one table for now. All I want to do is update a record-call the record NAME. The following is the coding I have done to establish the connection, data adapter, data set, data table, etc.
I just want to have a button that I can have the working code to update the database via the dataset. Any help is appreciated.
Thanks,
John
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Dim conn AsNew OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\people.mdb;User Id=;Password=;")
Dim da AsNew OleDb.OleDbDataAdapter
Dim ds AsNew DataSet
Dim sqlQuery AsString
sqlQuery = "Select * from [Names]"
da.SelectCommand = New OleDb.OleDbCommand(sqlQuery, conn)
'If I want to populate a datatable object outside of the DS object
'I can Dim a datatable and set it equal to the particular table (called "Names")
'which I added to the dataset (done on the right side of the equation)
'Supposedly, specifying the datatable name in the fill method of the dataset object
'will create and load the datatable so I don't have to explicitly use an "Add"
'method as I have done below.
Dim Names As DataTable = ds.Tables.Add("Names")
da.Fill(ds, "Names")
Dim dRow As DataRow
Dim dCol As DataColumn
ForEach Names In ds.Tables
ForEach dRow In Names.Rows
ForEach dCol In Names.Columns
Console.WriteLine(dRow(dCol))
fName.Items.Add(dRow(dCol))
Next
Next
Next
fName.Text = dRow(dCol)
fName.Text = dRow.ItemArray(1)
EndSub
EndClass