Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

visual studio 2008 - datable miscommunication?

Status
Not open for further replies.

cdck

Programmer
Nov 25, 2003
281
US
I have a table in my dataset which is used to locally store and process a set of records for use with a form. The table is LocalInfoTables.TREEpartsTreed. I have a function running to update the data in that table based on a query tied to a SQL server. The function runs down one row at a time and changes the rows if the query finds related data. This is done by using a loop starting with:
Code:
For Each r As DataRow In LocalInfoTables.TREEpartsTreed.Rows
A dataset is created with the information to be used for the update, and then fields in the databale are updated based on the dataset. Below is the list of field changes as they occur:
Code:
d_Hist = dtHist.Rows(0)
                    r("AmtRun") = d_Hist("HowMany")
                    r("LastUnit") = d_Hist("LastUnit")
                    r("LIqty") = d_Hist("SNofUnits")
                    r("Remain") = d_Hist("Remain")
                    r("LIgen") = d_Hist("Remain")
This works fine for all fields except the last one, which should set LIgen. When the code executes, this line is highlighted and I get the error "Object reference not set to an instance of an object."

I've verified that the field does exist in the datable being updated, the name is correctly typed both places. If I comment out that line, the code fires without error, so the d_Hist("Remain") reference is not the issue, since it's used on the line before this one to set r("Remain"). I tried deleting and resetting the line to make sure I didn't have any typos, and I refreshed the dataset. But it does not appear to see this field. Can anyone suggest a possible fix?

Cheryl dc Kern
 
Try this:

r("LIgen") = r("Remain")



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Solved. Although the error was thrown at the line listed above, it appears that there was actually something wrong with the control on the datarepeater. Dropping the datasource for that control back into it did not fix the issue, but deleting the control entirely and adding it again did.

I've had similar problems with datarepeaters before, where the fields get messed up and display incorrectly, and can only be fixed by replacing the controls or possibly the datarepeater in its entirety.

Cheryl dc Kern
 
jebenson: I actually tried that while I was waiting for a response, but got the same error. I also tried setting the value of d_Hist("Remain") into a variable and then using the variable to set the two r() values, with the same result.

Thank you very much for taking the time to try to help.

Cheryl dc Kern
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top