I have a datagrid on a windows form that gets populated by a DataTable when a button is clicked. I am trying to use the values provided by a combobox and two DateTime Pickers to supply parameters to the SelectCommand of the DataAdapter. Whenever I click the button I keep getting this error:
Input string not in the correct format.
Here is the Sub for the button's click event.
I haven't been very successful using SqlCommands with parameters. Can someone point me in the right direction?
Input string not in the correct format.
Here is the Sub for the button's click event.
Code:
Private Sub btnLoad_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnLoad.Click
'Define the string for the Select Command
Dim strSelectSQL As String = "SELECT * FROM tbl_Time_Record " & _
"WHERE (EmployeeID = @EmployeeID) AND " & _
"([Date Worked] >= @StartDate) AND " & _
"([Date Worked] <= @EndDate)"
'Define SqlDataAdapter
Dim daEntries As SqlDataAdapter = New SqlDataAdapter
'Define new SqlCommand
Dim cmdSelect As SqlCommand = New SqlCommand(strSelectSQL, Me.oConnTimetracker)
'Set the SelectCommand property of the DataAdapter
daEntries.SelectCommand = cmdSelect
'Add Typed Parameters to the SelectCommand
cmdSelect.Parameters.Add("@EmployeeID", _
SqlDbType.Int).Value = Me.cboEmployees.ValueMember
cmdSelect.Parameters.Add("@StartDate", _
SqlDbType.DateTime).Value = Me.dtpStartDate.Value
cmdSelect.Parameters.Add("@EndDate", _
SqlDbType.DateTime).Value = Me.dtpEndDate.Value
'Define a new dataset
Dim dsEntries As DataSet = New DataSet
'Fill the dataset and set the datagrid's datasource
daEntries.Fill(dsEntries)
Me.cboEmployees.DataSource = dsEntries.Tables("tbl_Time_Record")
End Sub