Solved

Compare string in dataset

Posted on 2004-09-20
24
285 Views
Last Modified: 2012-05-05
I need to compare a string that is changing with a mouse event

I need to compare that string to a column in a dataset, if they are equal then call sub.

I know how to do it with ado
while not eof
Record.Next,  blah blah, blah


pnmainIndex = Me.DbDataSet.T_PARTS.Columns.IndexOf("PART_NUM")
            pnmain = Me.DbDataSet.T_PARTS.Rows(gridRow)(pnmainIndex).ToString



 Private Sub show_parent()
        parent_lbl.Show()
        parent_btn.Show()

    End Sub
    Private Sub show_child()
        child_lbl.Show()
        child_btn.Show()

    End Sub
    Private Sub parent_lookup()
   ??? While not EOF
 ???    If pnmain = Me.Childdataset.T_PRNT_CHLD.CHLD Then
     
 show_parent()
End While
        End If
    End Sub

Here is the query
Me.OleDbSelectCommand2.CommandText = "SELECT DISTINCT CHLD FROM T_PRNT_CHLD"

Im getting the string, I just cant figure out how to see if that string exists in the other dataset, while checking all the records
0
Comment
Question by:malanois
  • 15
  • 9
24 Comments
 
LVL 7

Expert Comment

by:natloz
ID: 12106346
I use views to seach datasets....example...

'Associate the dataview
dvMainGrid.Table = oDsGrid.Tables("tblTester")

'Apply a filter against any of the columns in View...
dvMainGrid.RowFilter = [varLongSupplierName] Like '" & txtSupplier.Text & "'"
0
 
LVL 7

Expert Comment

by:natloz
ID: 12106391
It is sort of like a WHERE Sql statement begin put against a table in a dataset...then you can do the following...

Dim drv As DataRowView 'Data Row View object to query DataView object

dvMainGrid.RowFilter = [varLongSupplierName] Like '" & txtSupplier.Text & "'"

For Each drv In dvMaintenance
                _dteDateModified = drv("dteDateModified")
                count = count + 1
                etc...etc...sort of like looping through a recordset....but it is a filtered view of a dataset
Next
0
 
LVL 7

Expert Comment

by:natloz
ID: 12106395
sorry dvMaintenance...should be....dvMainGrid in the previous post...
0
 

Author Comment

by:malanois
ID: 12106633
that would be nice,

however I am not showin the sencond dataset,  I am only using it to see if pnamin is located in the dataset CHLD
0
 
LVL 7

Expert Comment

by:natloz
ID: 12106654
What do you mean you are not showing it?
0
 
LVL 7

Expert Comment

by:natloz
ID: 12106658
A view does not necessarily mean it is visible...????
0
 
LVL 7

Expert Comment

by:natloz
ID: 12106670
Don't let the "Grid" part of my previous posts throw you....that is just the name of a dataset that contains tables that I use to sometimes display in grids....a view is just a single relation to ONE table in your dataset...then you can do the loop as I showed above...
0
 

Author Comment

by:malanois
ID: 12108275
This is what i have done.

 Public Sub look()
        Dim _pnmain
        Dim count As Integer


        'Associate the dataview
        Dim dataview As New DataView

        DataView.Table = Me.Childdataset.Tables("CHLD")

        'Apply a filter against any of the columns in View...
        ' dataview.RowFilter = pnmain

        For Each drv In dataview
            _pnmain = drv("CHLD")
            count = count + 1
            If pnmain = _pnmain Then
                show_child()
            Else
                hide_child()
            End If

        Next
    End Sub

I do not want to apply a filter as this is the only thing i am looking for.

However it is not show my lbl and buuton from my show_child
I know i am clicking a row that has a match to pnmain and it is in the PRNT_CHLD table

I think this may be the problem, pnmain changes everytime the user clicks from the mouse down event.

I am calling look on form1 Load

is this correct??

Thanks for the HELP

MJ
0
 
LVL 7

Accepted Solution

by:
natloz earned 500 total points
ID: 12112299
Public Sub look()
        Dim _pnmain as string
        Dim drv As DataRowView 'Data Row View object to query DataView object

        'Associate the dataview
        Dim dataview As New DataView
        DataView.Table = Me.Childdataset.Tables("CHLD")

        'Apply a filter against any of the columns in View...
        dataview.RowFilter = [CHLD] Like '" & pnMain & "'"

        For Each drv In dataview
            _pnmain = CStr(drv("CHLD"))

            If pnmain = _pnmain Then
                show_child()
            Else
                hide_child()
            End If
        Next
    End Sub

Try something like this....you don't need COUNT unless you need a count for something...
0
 
LVL 7

Expert Comment

by:natloz
ID: 12112332
So your table is called CHLD and there is a Column called CHLD within that table?

Because that is what you are saying with drv("CHLD"))...

It is on a per column basis...so if table CHLD has columns PKID, VARNAME, VARPHONE

You would retrieve values with...(these are just samples...)

_pnMain = CStr(drv("PKID"))
_pnMain = CStr(drv("VARNAME"))
_pnMain = CStr(drv("VARPHONE"))
0
 

Author Comment

by:malanois
ID: 12112955
no my table is called T_PARENT_CHLD
Column is CHLD

I just tried it, with
 drv("CHLD"))
and
 drv("T_PARENT_CHLD"))

Something else is happening,
when i use the look()
it is adding a vertical and horitontal scroll bar when i do my searches, and it stays there.
if i do not use the look() it is just fine
0
 
LVL 7

Expert Comment

by:natloz
ID: 12112976
Public Sub look()
        Dim _pnmain as string
        Dim drv As DataRowView 'Data Row View object to query DataView object

        'Associate the dataview
        Dim dataview As New DataView
        DataView.Table = Me.Childdataset.Tables("T_PARENT_CHLD") <-------THIS WOULD BE TABLE IN DATASET

        'Apply a filter against any of the columns in View...
        dataview.RowFilter = [CHLD] Like '" & pnMain & "'"

        For Each drv In dataview
            _pnmain = CStr(drv("CHLD")) <-------THESE WOULD BE COLUMNS OF TABLE IN DATASET

            If pnmain = _pnmain Then
                show_child()
            Else
                hide_child()
            End If
        Next
    End Sub
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:malanois
ID: 12113292
still not working
0
 
LVL 7

Expert Comment

by:natloz
ID: 12113299
Could you post your code where you fill the Dataset.
0
 

Author Comment

by:malanois
ID: 12113364
I must have the look() inb the wrong place, as it is not calling hide_child() either

0
 
LVL 7

Expert Comment

by:natloz
ID: 12113377
When is it supposed to be fired?
0
 
LVL 7

Expert Comment

by:natloz
ID: 12113388
You should do it after the form loads because the data might not be in place yet...
0
 

Author Comment

by:malanois
ID: 12113741
It has to be fired everytime someone clicks on a row in the datagrid.  Thats when pnmain is being filled to a string.


Still not after this

  ' This sub creates an event for the selected rows
    Private Sub datagridClick(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles DataGrid.MouseDown
        look()        <---------------------------------------------------------I put it here thinking it may fire on the dataclick
        Dim mouseClick As DataGrid.HitTestInfo
        Dim descIndex As Integer
        Dim picIndex As Integer
        Dim pnmainIndex As Integer


        If e.Button = MouseButtons.Left Then
            dgObservation = CType(sender, DataGrid)
            mouseClick = DataGrid.HitTest(e.X, e.Y)
            gridRow = mouseClick.Row

            'Get variable of selected rows

            On Error Resume Next
            PnIndex = Me.DbDataSet.T_PARTS.Columns.IndexOf("TRDB_PN")
            Pnname = Me.DbDataSet.T_PARTS.Rows(gridRow)(PnIndex).ToString

            pnmainIndex = Me.DbDataSet.T_PARTS.Columns.IndexOf("PART_NUM")
            pnmain = Me.DbDataSet.T_PARTS.Rows(gridRow)(pnmainIndex).ToString

            descIndex = Me.DbDataSet.T_PARTS.Columns.IndexOf("TRDB_DESC")
            descname = Me.DbDataSet.T_PARTS.Rows(gridRow)(descIndex).ToString

            ImageIndex = Me.DbDataSet.T_PARTS.Columns.IndexOf("Image")

            'This is for the null value of the image column
            On Error Resume Next

            'get path for image file
            imgname = Me.DbDataSet.T_PARTS.Rows(gridRow)(ImageIndex).ToString


            'Compose the picture's file name.
            Dim file_name As String = Application.ExecutablePath
            If online = True Then
                file_name = ("Z:\TRDB2\Image\" + imgname)
            Else

                file_name = ("C:\TRDB2\Image\" + imgname)
            End If
            'Load the picture into a Bitmap.
            Dim bm As New Bitmap(file_name)

            ' Display the results.
            Me.picbx1.Image = bm


            selrow = (Pnname) + "  " + (descname)

        End If
    End Sub

    Public Sub frm_search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '  hide_child()
        ' hide_parent()
        hideimage()


        Dim DriveLetter As String
        Dim AllDrives As New ArrayList
        For Each DriveLetter In IO.Directory.GetLogicalDrives()
            Console.WriteLine(DriveLetter)
            AllDrives.Add(DriveLetter.Substring(0, 1))
        Next
        On Error Resume Next

        If Not AllDrives.Contains("Z") Then
            Dim net
            net = CreateObject("WScript.Network")
            net.MapNetworkDrive("Z:", "\\winn\gssectssec")

        End If


        If AllDrives.Contains("Z") Then
            online = True
            MessageBox.Show("Online Database is Connected")

        Else
            online = False
            MessageBox.Show("Local Database is Connected")


        End If

        ' On page load add databinding for the spins desc
        Me.spins_txt.DataBindings.Add("text", Me.DbDataSet.Tables(0), "DESC")

        ' lets hide columns from view in our DataSet
        Me.DataGrid.TableStyles(0).GridColumnStyles("DESC").Width = 0
        'Me.DataGrid.TableStyles(0).GridColumnStyles("Image").Width = 0
        Me.DataGrid.TableStyles(0).GridColumnStyles("Part_Num").Width = 10
        If online = True Then
            online_txt.Text = "ONLINE"
        Else
            online_txt.Text = "OFFLINE"


        End If

        Me.OleDbDataAdapter2.Fill(Me.Childdataset)

    End Sub
    ' get values of dfavorites array
    Private Sub FillItems(ByVal cmb As ComboBox)
        Dim i As Integer
        For i = 0 To al.Count - 1
            search_txt.Items.Add(al(i))
        Next
    End Sub
    Private Sub hide_parent()
        parent_lbl.Hide()
        parent_btn.Hide()

    End Sub
    Private Sub hide_child()
        child_lbl.Hide()
        child_btn.Hide()

    End Sub
    Private Sub show_parent()
        parent_lbl.Show()
        parent_btn.Show()

    End Sub
    Private Sub show_child()
        child_lbl.Show()
        child_btn.Show()

    End Sub

    Public Sub look()
        Dim _pnmain As String
        Dim drv As DataRowView 'Data Row View object to query DataView object

        'Associate the dataview
        Dim dataview As New DataView
        dataview.Table = Me.Childdataset.Tables("T_PRNT_CHLD")

        'Apply a filter against any of the columns in View...
        dataview.RowFilter = "[CHLD] Like '" & pnmain & "'"

        For Each drv In dataview
            _pnmain = CStr(drv("CHLD"))

            If pnmain = _pnmain Then
                show_child()
            Else
                hide_child()
            End If
        Next
    End Sub
0
 
LVL 7

Expert Comment

by:natloz
ID: 12114444
You should set a BREAKPOINT on the look() portion of your code and see if it is being invoked when you click...use F10 to step through the Code...and hit F11 when you are on look to step into the function...hold your mouse over values to see what they are when it is in the function....
0
 
LVL 7

Expert Comment

by:natloz
ID: 12114488
I think there is quotes missing here.....in front of [CHLD]
 
dataview.RowFilter = "[CHLD] Like '" & pnMain & "'"
0
 

Author Comment

by:malanois
ID: 12114527
I was just doing that,

no matter at what point im at _pnmain is always video,  which is the last row in the column(CHLD)
0
 

Author Comment

by:malanois
ID: 12115514
I think, maybe from debugging that it is not stopping when it does find the code

  For Each drv In dataview
            _pnmain = CStr(drv("CHLD"))

            If pnmain = _pnmain Then  <----------------They do match, but it keeps going through the for each loop
                show_child()
            Else
                hide_child()
            End If
        Next
    End Sub
0
 

Author Comment

by:malanois
ID: 12115605
Ahhhhhhhhhhh

that was it

For Each drv In dataview
            _pnmain = CStr(drv("CHLD"))

            If _pnmain = pnmain Then
                show_child()
                Exit For  <------------------

            Else
                hide_child()
            End If

        Next

Thank you for all of your help, it is so nice to see you follow this through.

KUDOS to YOU


MJ
0
 
LVL 7

Expert Comment

by:natloz
ID: 12115830
Glad to be of assistance.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now