I have asked similar questions before but I always get stuck on updating data.
On my form all the controls are bound at runtime (in form load event) to a dataview. Changes are made to the dataview via the controls and they should be saved to the database when the 'save' button is clicked.
This is the code I have but it doesn't work, I have tried every combination I can think off but just can't get it working which is very frustrating. Can somebody please tell me what I am doing wrong? I am so confused!
In the Public class bit at the top of my form I have have this:
Dim sqlStr As String = "Select LastName + ', ' + FirstName as Name, FirstName, LastName, Initials, ACode, JobTitle, GradeID, DateJoined, DateLeft, HrsPerWeek, CurrentChargeRate FROM tblStaff" 'FirstName, Initials, JobTitle, DateJoined, DateLeft, UnitsPerWeek, CurrentChargeRate, TeamID, TeamLeader, WorkingHoursFrom, WorkingHoursTo, Active, FullTime, Returning FROM tblStaff"
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sqlStr, conTRS)
Dim dsJJ As DataSet = New DataSet
Dim staffDV As DataView
Dim cb As New OleDb.OleDbCommandBuilder(da)
In the form load I have this:
'dataadaptor and dataset declared at top of form as public
'Dataview declared at top of form as public
staffDV = New DataView(dsJJ.Tables("Staff"), "HrsPerWeek = 145", "Name", DataViewRowState.CurrentRows)
cbxStaffName.DataSource = staffDV
cbxStaffName.DisplayMember = "Name"
cbxStaffName.ValueMember = "HrsPerWeek"
Me.txtFirstName.DataBindings.Add("Text", staffDV, "FirstName")
On the save button I have this:
Dim tbl As DataTable = dsJJ.Tables("Staff")
staffDV = tbl.DefaultView