shootsnlad Posted September 22, 2003 Posted September 22, 2003 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! Quote
Moderators Robby Posted September 23, 2003 Moderators Posted September 23, 2003 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 Quote Visit...Bassic Software
shootsnlad Posted September 23, 2003 Author Posted September 23, 2003 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. Quote
Moderators Robby Posted September 23, 2003 Moderators Posted September 23, 2003 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. Quote Visit...Bassic Software
shootsnlad Posted September 23, 2003 Author Posted September 23, 2003 (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 November 27, 2005 by PlausiblyDamp Quote
*Experts* Nerseus Posted September 24, 2003 *Experts* Posted September 24, 2003 Are you filling the DataSet somewhere else? I don't see any code that fills objMeter. -ner Quote "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
shootsnlad Posted September 25, 2003 Author Posted September 25, 2003 That's it. I never copied that particular group of coding. Thanks a lot. It always seems to be the simplest things. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.