简体   繁体   中英

asp.net data table add row doesn't and no error returned in vb.net

I have a data table that is loaded from an excel spreadsheet, which works fine. I then want to remove the duplicates from the table, which I can also accomplish. Next I want to add new rows which is where the whole thing goes wonky. The code runs and no errors are returned. (I have Try/Catch statements in place and they never get triggered).

Here is the code that tries to add the new row to the data table.

        newDRow = dtTemp.NewRow
        newDRow("QTY") = Convert.ToInt32(dupList(1))
        newDRow("GRATING-ID") = newMarkNum
        newDRow("GRATING SPAN DECIMAL INCHES") = Convert.ToDecimal(dupList(2))
        newDRow("GRATING WIDTH DECIMAL INCHES") = Convert.ToDecimal(dupList(3))
        Try
            dtTemp.Rows.Add(newDRow)
        Catch ex As Exception
            message = HttpUtility.JavaScriptStringEncode(ex.Message)
        End Try

The data table is called dtTemp. I have put break points in and can verify that each of the new row columns are getting the correct data.

The original data table is being passed to this function as follows:

Private Function RemoveDuplicate(ByVal dtInput As DataTable) As DataTable

I have a line that copies the dtInput table to the dtTemp table like so:

Dim dtTemp As DataTable = dtInput.Copy()

I just can't seem to find out why the row insert is not working. When the function runs and the data grid view is populated I see the results of removing the duplicate lines but the new lines are not in the table.

Any ideas?

Update #1-------------- I checked the table contents after the inserts were supposed to have happened but they do not show up. there should be a line that says:

2|1121-G31|32.875|42

And a line that says

7|1185-G33|22|22

But they are not there.

在此处输入图片说明

So I figured out what stupid mistake I was doing.

I had my new data row statement OUTSIDE of the For loop that was adding the new rows to the data table.

Moved it inside the for loop and it works great now!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM