Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating the database and Data Row Views

Status
Not open for further replies.

kimprogrammer

Programmer
Sep 15, 2008
160
CA
Hello
I'm want to update a database and am having problems with the datarowviews - I've tried a few things an am getting compile errors.

Thanks Again.
-----------------------------------------

'
'save Paycodes to database
'
Private Sub btnConfirm_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles btnConfirm.Click

'initialize variables

Dim Temptime As Decimal

Dim Hours As Decimal
Dim Minutes As Decimal

Dim StartDate As Date
Dim EndDate As Date

StartDate = DateTime.Parse(Me.cboPPStart.Text)
EndDate = StartDate.AddDays(14)

'TODO: This line of code loads data into the '_keyscan_payrollDataSet.SwipeAccumulativeHours' table. You can move, or remove it, as needed.
Me.SwipeAccumulativeHoursTableAdapter.FillByPayPeriodEmployee(Me._keyscan_payrollDataSet.SwipeAccumulativeHours, StartDate, EndDate, Employee)

'Dim newSwipeAccumulativeHoursRow As _keyscan_payrollDataSet.SwipeAccumulativeHoursRow
'newSwipeAccumulativeHoursRow = _keyscan_payrollDataSet.SwipeAccumulativeHours.newSwipeAccumulativeRow
Dim drvSwipeAccumulativeHoursRow As New DataRow()

'assign SwipeAccumulativeHours the employee number
newSwipeAccumulativeHoursRow.EmpNum = Me.cboEmployee.Text


'save supervisor Adjustment 1
Dim strReasoncode As String
Dim drReason As DataRow
For x As Integer = 1 To 14
If Me.txtAdjHour1(x).Text <> "" Or Val(Me.cboAdjMin1(x).Text) <> 0 Then
With drvSwipeAccumulativeHoursRow
.PPDay = CType(Me.lblPPDay(x).Text, Date)
strReasoncode = CStr(Me.cboAdjReason1(x).Text)
drReason = _keyscan_payrollDataSet.Supervisor_Reason_Xref.FindBySupReasonCode(strReasoncode)
.PayCode = (drReason("Paycode").ToString)
.SupReasonCode = Me.cboAdjReason1(x).Text
.InputType = "2"
Temptime = 0
Hours = CDec(Me.txtAdjHour1(x).Text)
Minutes = CDec(Me.cboAdjMin1(x).Text)
Select Case Minutes
Case 15
Minutes = CDec(0.25)
Case 30
Minutes = CDec(0.5)
Case 45
Minutes = CDec(0.75)
End Select
Temptime = Hours + Minutes
.Hours = Temptime
.Userid = Environment.UserName
.Timestamp = Now
_keyscan_payrollDataSet.SwipeAccumulativeHours.Rows.Add(newSwipeAccumulativeHoursRow)
End With
End If
Next

Try
Me.SwipeAccumulativeHoursBindingSource.EndEdit()
Me.SwipeAccumulativeHoursTableAdapter.Update(Me._keyscan_payrollDataSet.SwipeAccumulativeHours)
MessageBox.Show("Update successful", "", MessageBoxButtons.OK)
Catch ex As Exception
MessageBox.Show("Update failed - Try Again", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

'ClearForm()

End Sub
 
On line Dim drvSwipeAccumulativeHoursRow As New DataRow()

I get:System.Data.datarow.protected Sub (new(builder as system.data.datarow.builder) is not accessible in this context because it is protected

on Line: newSwipeAccumulativeHoursRow.EmpNum = Me.cboEmployee.Text which I have nowchanged to adjSwipeAccumulativeHoursRow tells me EmpNum is not a member
- so I know I still need to do something else.
 
Remove New before DataRow, and try this for the other line.
Code:
adjSwipeAccumulativeHoursRow("EmpNum") = Me.cboEmployee.Text
 
I've removed the NEW in the row "Dim drvSwipeAccumulativeHoursRow As New DataRow()"
and changed the code you suggested to
drvSwipeAccumulativeHoursRow("EmpNum") = CInt(Me.cboEmployee.Text)


I get an error saying cannot conver string to integer - I've tried CInt and Integer.parse with the same results

This field is VarChar in the SQL database and it is a key.
 
Did you check the data type on the DataColumn where the DataSet is defined and make sure it is also varchar?
 
I have not set up a datacolumn.
I have used a table adapter to open the dataset/table (_keyscan_payrollDataSet.SwipeAccumulativeHours),I want, I then what to write a record to it. I didn't think I needed to create a whole new table.
I'm just teaching myself VB.net so I'm not to sure exactly how all of this works.

 
Did you create your dataset with the wizard or in code? I rarely use the wizard, but if you created it that way, the dataset designer will show the types of each of the datacolumns.

If you don't have a strongly typed dataset, you shouldn't be getting that error until you update the database.
 
I do have the dataset created through the wizard (data source)
I appreciate your help - but if you are not to familiar with how this works maybe someone else could help me with it.

Ive reattached my code. I do have a different error now that I've made some changes and would appreciate it if someone could tell me what I'm missing.

The error now says 'Argument not specified for parameter 'rb' of Friend Sub New(rb as System.Data.DataRowBuilder)
----------------------------------------------------------
Private Sub btnConfirm_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles btnConfirm.Click

'initialize variables

Dim Temptime As Decimal

'Dim Temptime1 As Char
Dim Hours As Decimal
Dim Minutes As Decimal

Dim StartDate As Date
Dim EndDate As Date
Dim Employee As String

StartDate = DateTime.Parse(Me.cboPPStart.Text)
EndDate = StartDate.AddDays(14)
Employee = Me.cboEmployee.Text

'TODO: This line of code loads data into the '_keyscan_payrollDataSet.SwipeAccumulativeHours' table. You can move, or remove it, as needed.
Me.SwipeAccumulativeHoursTableAdapter.FillByPayPeriodEmployee(Me._keyscan_payrollDataSet.SwipeAccumulativeHours, StartDate, EndDate, Employee)

Dim newSwipeAccumulativeHoursRow As New _keyscan_payrollDataSet.SwipeAccumulativeHoursRow


'assign SwipeAccumulativeHours the employee number
newSwipeAccumulativeHoursRow.EmpNum = Me.cboEmployee.Text

'save supervisor Adjustment 1
Dim strReasoncode As String
Dim drReason As DataRow
For x As Integer = 1 To 14
If Me.txtAdjHour1(x).Text <> "" Or Val(Me.cboAdjMin1(x).Text) <> 0 Then
With newSwipeAccumulativeHoursRow
.PPDay = CType(Me.lblPPDay(x).Text, Date)
strReasoncode = CStr(Me.cboAdjReason1(x).Text)
drReason = _keyscan_payrollDataSet.Supervisor_Reason_Xref.FindBySupReasonCode(strReasoncode)
.PayCode = (drReason("Paycode").ToString)
.SupReasonCode = Me.cboAdjReason1(x).Text
.InputType = "2"
Temptime = 0
Hours = CDec(Me.txtAdjHour1(x).Text)
Minutes = CDec(Me.cboAdjMin1(x).Text)
Select Case Minutes
Case 15
Minutes = CDec(0.25)
Case 30
Minutes = CDec(0.5)
Case 45
Minutes = CDec(0.75)
End Select
Temptime = Hours + Minutes
.Hours = Temptime
.Userid = Environment.UserName
.Timestamp = Now
_keyscan_payrollDataSet.SwipeAccumulativeHours.Rows.Add(newSwipeAccumulativeHoursRow)
End With
End If
Next
-------------------------------------------------------
 
I will start a new thread for this because it is too long for someone to go thru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top