J
John
Hi
I have a WinForm app with a bound form. When user enters a value in field
rateid I lookup the respective rate amount from a table and assign it to
field rate.I am using the DLookup function to achieve this (full code given
below). This function returns a value of type object so I need to convert it
to string. If I use the function as below (using ToString) it works fine;
Me.txtRate.Text = DLookup(<parameters here>).ToString
but if I use it with a CStr
Me.txtRate.Text = CStr(DLookup(<parameters here>))
and then browse through 2-3 record the form stops showing data in the bound
fields. This brings me to question; what is the difference between CStr and
tostring that could be causing the above problem?
Thanks
Regards
=======
Function DLookup(ByVal SearchFld As String, ByVal SearchTbl As String, ByVal
SearchCriteria As String) As Object
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Cmd = New OleDb.OleDbCommand("SELECT " & SearchFld & " FROM " & SearchTbl
& " WHERE " & SearchCriteria, DBConnection())
Reader = Cmd.ExecuteReader()
If (Reader.Read()) Then
DLookup = Reader.GetValue(0)
Else
DLookup = DBNull.Value
End If
Reader.Close()
Reader = Nothing
Cmd = Nothing
End Function
I have a WinForm app with a bound form. When user enters a value in field
rateid I lookup the respective rate amount from a table and assign it to
field rate.I am using the DLookup function to achieve this (full code given
below). This function returns a value of type object so I need to convert it
to string. If I use the function as below (using ToString) it works fine;
Me.txtRate.Text = DLookup(<parameters here>).ToString
but if I use it with a CStr
Me.txtRate.Text = CStr(DLookup(<parameters here>))
and then browse through 2-3 record the form stops showing data in the bound
fields. This brings me to question; what is the difference between CStr and
tostring that could be causing the above problem?
Thanks
Regards
=======
Function DLookup(ByVal SearchFld As String, ByVal SearchTbl As String, ByVal
SearchCriteria As String) As Object
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Cmd = New OleDb.OleDbCommand("SELECT " & SearchFld & " FROM " & SearchTbl
& " WHERE " & SearchCriteria, DBConnection())
Reader = Cmd.ExecuteReader()
If (Reader.Read()) Then
DLookup = Reader.GetValue(0)
Else
DLookup = DBNull.Value
End If
Reader.Close()
Reader = Nothing
Cmd = Nothing
End Function