i m using vb.net with oledb connection
when retrieving data from EMP database i m getting error as syntax error(comma) in query expression 'eno='1',lname='',fname='' And FromPay=## And ToPay=##'
plz help...
Private Sub PopulateNameList()
Dim Connection As New OleDbConnection(ACCESS_CONNECTION_STRING)
lvName.Items.Clear()
lvName.Sorting = SortOrder.Ascending
Dim cmdfill As New OleDbCommand("SELECT eno, lname & ', ' & fname as Name FROM EMP", Connection)
Try
Connection.Open()
Dim datareader As OleDbDataReader
datareader = cmdfill.ExecuteReader
While datareader.Read
Dim lvi As New ListViewItem
lvi.Text = CStr(datareader("eno"))
lvi.SubItems.Add(CStr(datareader("Name")))
lvName.Items.Add(lvi)
End While
If datareader.HasRows Then
lvName.TopItem.Selected = True
lvName.TopItem.Focused = True
lvName.TopItem.EnsureVisible()
lvName.Select()
'lvName.Items(0).Selected = True
'strSelectedeno = lvName.Items(0).SubItems(0).Text
' lvName_SelectedIndexChanged(Nothing, Nothing)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
Finally
Connection.Close()
End Try
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
mainform.Show()
End Sub
Private Sub lvName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvName.SelectedIndexChanged
Dim cnOleDb As OleDbConnection
Dim cmSQL As OleDbCommand
Dim drSQL As OleDbDataReader
Dim strSQL As String
'Dim strID As String
Dim ThisItem As ListViewItem
If IsNothing(lvName.FocusedItem) Then Exit Sub
For Each ThisItem In lvName.SelectedItems
strSelectedeno = lvName.Items(ThisItem.Index).SubItems(0).Text
Next
strSelectedeno = lvName.FocusedItem.Text
Try
strSQL = "SELECT eno," & _
"lname, " & _
"fname, " & _
"DailyRate, " & _
"Allowance, " & _
"Incentives " & _
"FROM EMP " & _
"WHERE eno = '" & strSelectedeno & "'"
cnOleDb = New OleDbConnection(ACCESS_CONNECTION_STRING)
cnOleDb.Open()
cmSQL = New OleDbCommand(strSQL, cnOleDb)
drSQL = cmSQL.ExecuteReader()
drSQL.Read()
txtDailyRate.Text = Format(Convert.ToDouble(drSQL.Item("DailyRate").ToString()), "0.00")
dblAllowance = Format(Convert.ToDouble(drSQL.Item("Allowance").ToString()), "0.00")
txtAllowance.Text = dblAllowance
dblIncentives = Format(Convert.ToDouble(drSQL.Item("Incentives").ToString()), "0.00")
txtIncentives.Text = dblIncentives
' Close and Clean up objects
drSQL.Close()
cnOleDb.Close()
cmSQL.Dispose()
cnOleDb.Dispose()
GetPayslip()
txtTotal.Text = Format(txtworkdays.Text * txtDailyRate.Text, "0.00")
Calc_Gross()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub
in above code i m getting the error as
syntax error(comma) in query expression 'eno='1',lname='',fname='' And FromPay=## And ToPay=##'.
i m not getting from where this error is coming.
plz help.