wwwMarvscom wwwMarvscom - 1 year ago 143
Vb.net Question

The expression contains invalid date constant

I tried this code first before copying it to my main project (I created new project to test the codes first):

Private Sub posBtn_Click(sender As Object, e As EventArgs) Handles posBtn.Click
On Error GoTo wewe

If posText.Text = "" Then
Call notFound()
Exit Sub

Else

Dim cantFind As String = posText.Text

EmployeesRecordBindingSource.Filter = "(Convert(#_of_Employees, 'System.String') LIKE '" & posText.Text & "')" & "OR (last_name LIKE '" & posText.Text & "') OR (first_name LIKE '" & posText.Text & "')" & "OR (mi LIKE '" & posText.Text & "') OR (position LIKE '" & posText.Text & "')"

If EmployeesRecordBindingSource.Count <> 0 Then
With DataGridView2
.DataSource = EmployeesRecordBindingSource
End With
Else

MsgBox(cantFind & vbNewLine & "The search item was not found!", MsgBoxStyle.Information, "Hey boss")

EmployeesRecordBindingSource.Filter = Nothing

With DataGridView2
.ClearSelection()
.DataSource = EmployeesRecordBindingSource
End With


End If
End If


lul:
Exit Sub

wewe:

MsgBox("Error Number " & Err.Number & vbNewLine & "Error Description " & Err.Description, MsgBoxStyle.Critical, "Reset Error!")
Resume lul

End Sub


In my sample project, this is working. But when I copied it to my main project and run, I got this error:
The expression contains invalid date constant '#_ofE_Employees, 'Sytem.String') LIKE '1')OR
and so on... Did I missed something? Btw, it is for searching in datagridview. I have also private sub for reset, notfound.

Answer Source

Fields cannot start with the # as it is used for dates.

You might reconsider using signs and numbers when creating fields and variables in both your platform and database because there are chances those are reserved.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download