Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a very frustrating problem and I am not sure why it is not working. I have the following code:

 

p = Me.BindingContext(objMeter, "Water_Meter").Count

 

Now 'p' should come back with the number of rows that is in the "Water_Meter" table. There are 4 rows, yet 'p' is always 0. ObjMeter is setup to reference a Meter dataset that is tied to that table. Why would it return 0? Even this returns 0:

 

p = Objmeter.Water_Meter.rows.count

 

I am very confused as this has worked in every other part of my program. I have tried recreating objmeter, and the meter dataset with no luck. I even went into the meter dataset and viewed the data and it pulls in the 4 rows. I can't figure out what is different about this one. Please help!

  • Moderators
Posted

If you have a dataview do this...

     Dim x As Integer = myDataview.Table.Rows.Count

if you have a dataset then...

     myDataview = myDataset.Tables(0).DefaultView
     Dim x As Integer = myDataview.Table.Rows.Count

Visit...Bassic Software
Posted
I tried that and did not have any luck. It still returns 0 rows. I just don't understand why it is not working. I have used the exact same method in the program on 6 or 7 other forms in the program. This particular one always returns 0 rows. I guess my only option is to figure out another way to get to the table. The wierdest thing is that I was using connecting to the same table on a different form, the exact same way, and then when I created a new form and tried to connect from that, it doesn't work. I'll probably just go back to my other form and use the connection from there. Thanks for the suggestions.
  • Moderators
Posted

I'm sure there is some method that is not exactly the same, these things are not intermitent, it either works or it does not.

 

Post the relevant code and we'll see if someone can spot the err.

Visit...Bassic Software
Posted (edited)

Public Class FrmMeterListBox
   Inherits System.Windows.Forms.Form
   Dim metar(50, 2) As String
   Dim numfound, p As Integer

Private Sub FrmMeterListBox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim reccount, i As Integer
       reccount = 0
       isfound = False
       numfound = 0
       For p = 1 To 50
           metar(p, 1) = ""
           metar(p, 2) = ""
       Next
       p = Me.BindingContext(objMeter, "Water_meter").Count
       Do Until (reccount = Me.BindingContext(objMeter, "Water_meter").Count)
           If IsDBNull(objMeter.Water_Meter.Rows(reccount).Item("tap_number")) Then
           Else
               If objMeter.Water_Meter.Rows(reccount).Item("tap_number") = tapnum Then
                   numfound = numfound + 1
                   If numfound = 1 Then
                       whereiam = reccount
                       isfound = True
                       metar(numfound, 1) = objMeter.Water_Meter.Rows(reccount).Item("ser_number")
                       metar(numfound, 2) = whereiam
                   ElseIf numfound > 1 And numfound < 51 Then
                       metar(numfound, 1) = objMeter.Water_Meter.Rows(reccount).Item("ser_number")
                       metar(numfound, 2) = reccount
                   End If
               End If
           End If
           reccount = reccount + 1
       Loop
       If numfound > 1 Then
           mlist.Items.Clear()
           For p = 1 To numfound
               mlist.Items.Add(metar(p, 1))
           Next
           MsgBox("There are multiple meters for this tap slip.  Please click OK and pick the one you want to display", MsgBoxStyle.OKOnly, "Multiple Meters")
           For p = 1 To numfound
               If metselect = metar(p, 1) Then
                   whereiam = metar(p, 2)
                   isfound = True
               End If
           Next
       End If
       Me.Hide()
       Try
           Dim mc As New frmMeterCard()
           mc.ShowDialog()
       Catch
       End Try
   End Sub
End Class


 

Now the 'p =' after the For...Next.. is the one that shows 0 rows. I just put that in there to test the next Do Until line. It skips by the do until because the reccount = 0. I have a dataset attached to this form called 'ObjMeter', which references a typed dataset called 'Meter'. If I double click on that in my solution explorer, my table is in there. I can also do a "Retrieve data from table' and it brings back my 4 rows. The name of the table in the database is "Water_Meter". Ideas?

Edited by PlausiblyDamp
  • *Experts*
Posted

Are you filling the DataSet somewhere else? I don't see any code that fills objMeter.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...