liquidspaces Posted November 26, 2002 Posted November 26, 2002 Ok. So all of you have been very helpful thus far. I've learned a lot. I owe each of you half of my paycheck. BUT I have one more problem in what has become a large series of problems. I'm trying to find and edit a specific record in a database. The table name is Shipping and the field is SHIP_FROM. The record number (which is the primary key) is stored in "lblBOLN.text". My code is below: Dim objRow As DataRow objRow = DataSet21.Tables("Shipping").Rows.Find(Val(lblBOLN.Text)) objRow.Item("SHIP_FROM") = txtName.Text When I execute this, it gets hung up on the above line. I receive the following error: "Object reference not set to an instance of an object." Also, when I run the debugger, it shows that the value of objRow is "NOTHING". If you could offer any help on this I would appreciate it. Maybe Rows.Find isn't doing what I think it's doing. Thanks, Kevin Quote
*Gurus* divil Posted November 26, 2002 *Gurus* Posted November 26, 2002 Rows.Find clearly isn't finding anything at all. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
liquidspaces Posted November 26, 2002 Author Posted November 26, 2002 But that's what I don't understand. I've double, triple, and quadruple checked to make sure that the row it's "looking" for is actually in the database. Is there a better way to edit the fields of a specific row? Quote
wyrd Posted November 26, 2002 Posted November 26, 2002 Hmm.. from the object browser.. Public Function Find(ByVal key As Object) As System.Data.DataRow Member of System.Data.DataRowCollection Summary: Gets the row specified by the primary key value. Parameters: key: The primary key value of the System.Data.DataRow to find. Return Values: A System.Data.DataRow containing the primary key value specified; otherwise a null value if the primary key value does not exist in the System.Data.DataRowCollection . As far as I can tell you are using it correctly, except that you're passing in an integer value which should be fine because it'll just box the value into an object. To avoid that overhead just pass in the lblBOLN.Text. Honestly if anything is causing the error it would be that (although I don't see why). Otherwise, what Divil said.. the key just doesn't exist. Make sure you are looking for the key in the correct table and database :) Then again I'm not familiar with database stuff in .NET, so there could be something obvious that I'm missing that you can probably see just from the info. I pasted from the object browser. When all else fails, consult the object browser. *nod* Quote Gamer extraordinaire. Programmer wannabe.
liquidspaces Posted November 26, 2002 Author Posted November 26, 2002 Awesome! Got it working now. The problem was with the dataadapter configuration. Thanks all for your help!!!! 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.