G
Gary Paris
I am pretty new at .NET and am reading a book on ADO.NET but I need some
help.
I have the following code in the Load routine of a sample program. I would
like to read in some data and take the first row and put a few fields on a
form. Then I would like to update the data. How on earth can I update the
rows when I call an update routine? The table and datarow are defined in
the Load routine and are not global. If I have another routine, how can I
put the text fields into the table and do an update?
Should be simple, but my poor little brain is on overload. HELP
Thanks,
Gary
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\adonetsbs\SampleDBs\nwind.mdb;"
Dim cn As New OleDb.OleDbConnection(strConn)
Dim strSQL As String
strSQL = "SELECT EmployeeID, FirstName, LastName, Address, City,
Region, " & _
"PostalCode from Employees ORDER BY LastName, FirstName"
Dim da As New OleDb.OleDbDataAdapter(strSQL, strConn)
Dim ds As New DataSet
da.Fill(ds, "Employees")
cmbLastName.DataSource = ds.Tables(0)
cmbLastName.DisplayMember = "LastName"
cmbLastName.ValueMember = "EmployeeID"
Dim tbl As DataTable = ds.Tables(0)
Dim rowEmployee As DataRow = tbl.Rows(0)
txtFirstName.Text = rowEmployee("FirstName")
txtLastName.Text = rowEmployee("LastName")
txtAddress.Text = rowEmployee("Address")
End Sub
help.
I have the following code in the Load routine of a sample program. I would
like to read in some data and take the first row and put a few fields on a
form. Then I would like to update the data. How on earth can I update the
rows when I call an update routine? The table and datarow are defined in
the Load routine and are not global. If I have another routine, how can I
put the text fields into the table and do an update?
Should be simple, but my poor little brain is on overload. HELP
Thanks,
Gary
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\adonetsbs\SampleDBs\nwind.mdb;"
Dim cn As New OleDb.OleDbConnection(strConn)
Dim strSQL As String
strSQL = "SELECT EmployeeID, FirstName, LastName, Address, City,
Region, " & _
"PostalCode from Employees ORDER BY LastName, FirstName"
Dim da As New OleDb.OleDbDataAdapter(strSQL, strConn)
Dim ds As New DataSet
da.Fill(ds, "Employees")
cmbLastName.DataSource = ds.Tables(0)
cmbLastName.DisplayMember = "LastName"
cmbLastName.ValueMember = "EmployeeID"
Dim tbl As DataTable = ds.Tables(0)
Dim rowEmployee As DataRow = tbl.Rows(0)
txtFirstName.Text = rowEmployee("FirstName")
txtLastName.Text = rowEmployee("LastName")
txtAddress.Text = rowEmployee("Address")
End Sub