Nov 2nd, 2005, 06:16 PM
#1
Thread Starter
Hyperactive Member
[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)
Nov 2nd, 2005, 06:50 PM
#2
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()
Nov 2nd, 2005, 06:56 PM
#3
Thread Starter
Hyperactive Member
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.
Nov 2nd, 2005, 07:11 PM
#4
Re: This Code searches Strings HOW to make it search Integer?
Cool. Don't forget to resolve your thread from the Thread Tools menu.
Nov 3rd, 2005, 04:09 PM
#5
Thread Starter
Hyperactive Member
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
Attached Images
Nov 3rd, 2005, 05:54 PM
#6
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.
Nov 3rd, 2005, 06:03 PM
#7
Thread Starter
Hyperactive Member
Re: [RESOLVED] This Code searches Strings HOW to make it search Integer?
Yes sir EmployeePassword column is an Integer, what can I do?
Nov 3rd, 2005, 06:24 PM
#8
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.
Nov 3rd, 2005, 06:27 PM
#9
Thread Starter
Hyperactive Member
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
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width