Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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?

Posted

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*

Gamer extraordinaire. Programmer wannabe.

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...