[RESOLVED] This Code searches Strings HOW to make it search Integer?
It works just fine for searching strings, can someone help me modify it to search for Integers?
Button Click:
VB Code:
Private Sub btnLogOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogOn.Click
Try
Dim validateUserLogOn As Data.DataView = New Data.DataView(DatabaseMainPressDataSet.tblPasswords)
validateUserLogOn.RowFilter = "EmployeeFirstName like '%" + txtEnterPassword.Text + "%'"
Dim matchFound As Integer = validateUserLogOn.Count
Select Case matchFound
Case 0
textLabelOnDialogForm = "El Sistema no reconoce la clave entrada?"
frmDialog.ShowDialog()
Case 1
frmLogOnSuccessful.EmployeeFirstNameParameter = CStr(validateUserLogOn.Item(0)("EmployeeFirstName"))
frmLogOnSuccessful.ShowDialog()
End Select
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Property:
VB Code:
Private m_EmployeeFirstNameParameter As String
Public WriteOnly Property EmployeeFirstNameParameter() As String
Set(ByVal value As String)
m_EmployeeFirstNameParameter = value
End Set
End Property
Form Load:
VB Code:
Me.TblPasswordsTableAdapter.FillByEmployeeFirstName(DatabaseMainPressDataSet.tblPasswords, Me.m_EmployeeFirstNameParameter)
Re: This Code searches Strings HOW to make it search Integer?
You just change the expression to which you set the RowFilter to include only rows where a particular column equals a particular value, e.g.:
VB Code:
myView.RowFilter = "MyColumn = " & myInt.ToString()
Re: This Code searches Strings HOW to make it search Integer?
Thanks jmcilhinney:
In my many tries and fails I was missing this piece of info: myInt.ToString()
Thanks again.
Re: This Code searches Strings HOW to make it search Integer?
Cool. Don't forget to resolve your thread from the Thread Tools menu.
1 Attachment(s)
Re: [RESOLVED] This Code searches Strings HOW to make it search Integer?
Do you know by any chance why I’m getting this error?
VB Code:
Private Sub btnLogOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogOn.Click
Try
Dim Clave As Integer = CInt(txtEnterPassword.Text)
Dim validateUserLogOn As Data.DataView = New Data.DataView(DatabaseMainPressDataSet.tblPasswords)
validateUserLogOn.RowFilter = "EmployeePassword like '%" + txtEnterPassword.Text + "%'"
Dim matchFound As Integer = validateUserLogOn.Count
Select Case matchFound
Case 0
textLabelOnDialogForm = "El Sistema no reconoce la clave entrada?"
frmDialog.ShowDialog()
Case 1
frmLogOnSuccessful.EmployeePasswordParameter = CInt(validateUserLogOn.Item(0)("EmployeePassword"))
frmLogOnSuccessful.ShowDialog()
End Select
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
VB Code:
Private m_EmployeePasswordParameter As Integer
Public WriteOnly Property EmployeePasswordParameter() As Integer
Set(ByVal value As Integer)
m_EmployeePasswordParameter = value
End Set
End Property
Private Sub frmLogOnSuccessful_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, MyBase.Load, MyBase.Load
Me.TblPasswordsTableAdapter.FillByEmployeePassword(DatabaseMainPressDataSet.tblPasswords, Me.m_EmployeePasswordParameter)
End Sub
Re: [RESOLVED] This Code searches Strings HOW to make it search Integer?
Is your EmployeePassword column an Integer? From the error message it would seem so, and you can only use LIKE and wildcards with text fields.
Re: [RESOLVED] This Code searches Strings HOW to make it search Integer?
Yes sir EmployeePassword column is an Integer, what can I do?
Re: [RESOLVED] This Code searches Strings HOW to make it search Integer?
You can't use the LIKE operator or wildcards with anything but text columns, plain and simple. Also, single quotes are only for string values, not numbers. If you want all records where a numerical value is within a range you can do something like this:
VB Code:
myView.RowFilter = String.Format("myNumberColumn >= {0} AND myNumberColumn <= {1}", minVal, maxVal)
I suggest that you read the help topic for the DataView.RowFilter property, which will point you to the DataColumn.Expression property for information on allowable values. It is very similar to standard SQL but not the same.
Re: [RESOLVED] This Code searches Strings HOW to make it search Integer?
Thanks for the great help. I trully appreciate it. I will check MSDN for DataView.RowFilter property.
piscis