Passing value of DataPicker control ?

While trying to get up to speed with Visual Basic 2005 Express and SQL Server 2005 Express I ran into the following problem and hope someone can explain to me what I can do to correct the problem.

I created the following SQL query in a Table Adapater (i.e. "WagesEarnedTableAdapter") with the name "ComputeHoursWorked". After creating it I tested it by typing in the values "1" for @EmployeeID and "1/21/2006" for @WeekEndingDate. Everything worked fine and the correct value was returned.

SELECT SUM(HoursWorked) AS HoursWorked

FROM Projects

WHERE (EmployeeID = @EmployeeID) AND (WeekEndingDate = @WeekEndingDate)

However when I call the routine using the following procedure, from a form that I created, I get an error saying "Nullable object must have a value.". In testing with different variations, I found that the error is happening because of the value I am passing from a DatePicker control "WagesWeekEndingDateTimePicker.Value". If I replace this argument with hard coded date the query runs fine. Using the DatePicker control info fails. DO I need to do some kind of conversion first

Private Sub PlusMinusHoursTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlusMinusHoursTextBox.TextChanged

Dim HoursWorked As Decimal

If Not DuringLoad Then

If IsNumeric(PlusMinusHoursTextBox.Text) Then

HoursWorked = CType(WagesEarnedTableAdapter.ComputeHoursWorked(EmployeeIDComboBox.SelectedValue, WagesWeekEndingDateTimePicker.Value), Decimal)

Else

MessageBox.Show("Plus Minus Hours field must be numeric. Please reenter.", "Invalid Value", MessageBoxButtons.OK)

PlusMinusHoursTextBox.Text = 0.0

End If

End If

End Sub



Answer this question

Passing value of DataPicker control ?

  • JSR

    What is the data type of WeekEndingDate

    Date, DateTime, String Try formatting the Datepicker output before passing it...

    ie...

    Me.DateTimePicker1.Value.ToShortDateString() or

    Me.DateTimePicker1.Value.Date...etc..

    HTH



  • Ben Avery

    Thanks for the quick response.

    The field in the table is defined as "datetime" and the "Allow Nulls" check box is unchecked. When the form opens, the correct value stored in the SQL table is displayed in the DatePicker control on the form..

    The DatePicker control however is defined with the "Format" property set to "ShortDate". WHen I hover the cursor over the actual code withing the call to the SQL query, the correct value seems to be there.

    I have tried both variations that you suggested and still am getting the same error message. I am starting to wonder if this is a small anololy in VB 2005 since it is so new.

    Afain, thanks for the help


  • Passing value of DataPicker control ?