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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot Set Value on First Row of DataTable

Status
Not open for further replies.

andrea96

Programmer
Jan 26, 2001
201
US
I am using a For Loop to set one column in every row of my DataTable to a certain value. It is working for all rows except the first one. Here is my code.

Code:
For i = 0 To dsWorkOrderFlex.Tables("WorkOrder").Rows.Count - 1
    dsWorkOrderFlex.Tables("WorkOrder").Rows(i)("kit_no") = strKitNo
Next

I have stepped through the code, and the value of "kit_no" is an empty string before and after it attempts to change the value for the first record (i=0). The code doesn't get an error, and "kit_no" in every row after the first one is set to strKitNo as expected. Any ideas on what is causing this?

Thanks,
Andrea
 
Try this

For Each r As DataRow In dsWorkOrderFlex.Tables("WorkOrder").Rows
r("kit_no") = strKitNo
Next
 
I tried, but had the same result. The first row remains an empty string and the following rows are correctly set to the strKitNo value. Thanks.

 
I changed the DataSet to a typed DataSet and retested. With the typed DataSet, the "kit_no" values are not set in any rows. Still no errors.

I changed it back to an untyped DataSet, and left the "kit_no" value as DBNull instead of changing it to an empty string before executing the code I originally posted. My original code changed the DBNull to the strKitNo value, so my issue is resolved.

 
My guess is that you have it databound to a form control. Try setting the bindings after the global update

Otherwise what has been suggested will definitely work


Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
Yes, it is bound to a grid in my form. The code I was having the trouble with is in my class that updates the database. This code is the last code that is executed for this DataSet before it updates the database, and I don't have the value for the kit no before this point. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top