Results 1 to 9 of 9

Thread: [RESOLVED] This Code searches Strings HOW to make it search Integer?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    Resolved [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:
    1. Private Sub btnLogOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogOn.Click
    2.  
    3.         Try
    4.             Dim validateUserLogOn As Data.DataView = New Data.DataView(DatabaseMainPressDataSet.tblPasswords)
    5.             validateUserLogOn.RowFilter = "EmployeeFirstName like '%" + txtEnterPassword.Text + "%'"
    6.  
    7.             Dim matchFound As Integer = validateUserLogOn.Count
    8.             Select Case matchFound
    9.                 Case 0
    10.                     textLabelOnDialogForm = "El Sistema no reconoce la clave entrada?"
    11.                     frmDialog.ShowDialog()
    12.                 Case 1
    13.                     frmLogOnSuccessful.EmployeeFirstNameParameter = CStr(validateUserLogOn.Item(0)("EmployeeFirstName"))
    14.                     frmLogOnSuccessful.ShowDialog()
    15.             End Select
    16.         Catch ex As Exception
    17.             MessageBox.Show(ex.ToString)
    18.         End Try
    19.  
    20.     End Sub

    Property:
    VB Code:
    1. Private m_EmployeeFirstNameParameter As String
    2.  
    3. Public WriteOnly Property EmployeeFirstNameParameter() As String
    4.         Set(ByVal value As String)
    5.             m_EmployeeFirstNameParameter = value
    6.         End Set
    7.     End Property
    Form Load:
    VB Code:
    1. Me.TblPasswordsTableAdapter.FillByEmployeeFirstName(DatabaseMainPressDataSet.tblPasswords, Me.m_EmployeeFirstNameParameter)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. myView.RowFilter = "MyColumn = " & myInt.ToString()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: This Code searches Strings HOW to make it search Integer?

    Cool. Don't forget to resolve your thread from the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    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:
    1. Private Sub btnLogOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogOn.Click
    2.  
    3.         Try
    4.             Dim Clave As Integer = CInt(txtEnterPassword.Text)
    5.             Dim validateUserLogOn As Data.DataView = New Data.DataView(DatabaseMainPressDataSet.tblPasswords)
    6.             validateUserLogOn.RowFilter = "EmployeePassword like '%" + txtEnterPassword.Text + "%'"
    7.  
    8.             Dim matchFound As Integer = validateUserLogOn.Count
    9.             Select Case matchFound
    10.                 Case 0
    11.                     textLabelOnDialogForm = "El Sistema no reconoce la clave entrada?"
    12.                     frmDialog.ShowDialog()
    13.                 Case 1
    14.                     frmLogOnSuccessful.EmployeePasswordParameter = CInt(validateUserLogOn.Item(0)("EmployeePassword"))
    15.                     frmLogOnSuccessful.ShowDialog()
    16.             End Select
    17.         Catch ex As Exception
    18.             MessageBox.Show(ex.ToString)
    19.         End Try
    20.  
    21.     End Sub

    VB Code:
    1. Private m_EmployeePasswordParameter As Integer
    2.  
    3.     Public WriteOnly Property EmployeePasswordParameter() As Integer
    4.         Set(ByVal value As Integer)
    5.             m_EmployeePasswordParameter = value
    6.         End Set
    7.     End Property
    8.  
    9.     Private Sub frmLogOnSuccessful_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, MyBase.Load, MyBase.Load
    10.  
    11.         Me.TblPasswordsTableAdapter.FillByEmployeePassword(DatabaseMainPressDataSet.tblPasswords, Me.m_EmployeePasswordParameter)
    12.  
    13.     End Sub
    Attached Images Attached Images  

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    Re: [RESOLVED] This Code searches Strings HOW to make it search Integer?

    Yes sir EmployeePassword column is an Integer, what can I do?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    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
  •  



Click Here to Expand Forum to Full Width