Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am adding 2 columns to a table that belongs to a dataset. I perform this operation twice. In grid1 i am able to successfully add only 1 column("RefNum") whereas in grid2 both columns get added perfectly. No exception is thrown. Its as if the adding of the second column to grid1 did not happen, even though when i step through the code it is being executed...

Try as i might, i am unable to identify why grid2 works perfectly whilst grid1 does not.

<pre lang="vb">Dim dataSetResults As DataSet
Dim foundRowsCancelling() As Data.DataRow
Dim foundRowsCancelled() As Data.DataRow

dataSetResults = ExecStoredProcThatReturnsDataSet("Stored_Proc")

'first grid
dsCancellingData = dataSetResults.Clone()
foundRowsCancelling = dataSetResults.Tables(0).Select("SystemStatus <> 'F'")

Dim cancellingTable As DataTable = dsCancellingData.Tables(0)

For Each cancellingRow As Data.DataRow In foundRowsCancelling

    If cancellingRow.Table.Columns.Contains("RefNum") Then

        If String.IsNullOrEmpty(cancellingRow("RefNum").ToString) Then
            cancellingRow("RefNum") = "None"
        Else
            cancellingRow("RefNum") = "<a target='_blank' href='http://www.google.com'>View</a>"
        End If
    Else
        cancellingRow.Table.Columns.Add("RefNum", GetType(String))
        cancellingRow("RefNum") = "None"
    End If

    If Not cancellingRow.Table.Columns.Contains("ViewLink") Then
        cancellingRow.Table.Columns.Add("ViewLink", GetType(String))
    End If

    If Not String.IsNullOrEmpty(cancellingRow("SystemID").ToString) Then
        cancellingRow("ViewLink") = "test1"
    Else
        cancellingRow("ViewLink") = "test2"
    End If

    cancellingTable.ImportRow(cancellingRow)
Next

dsCancellingData.DataSetName = "CancellingDataSet"
dsCancellingData.Tables(0).TableName = "CancellingTable"
'/first grid

'second grid
dsCancelledData = dataSetResults.Clone()
foundRowsCancelled = dataSetResults.Tables(0).Select("SystemStatus = 'Z'")

Dim cancelledTable As DataTable = dsCancelledData.Tables(0)

For Each cancelledRow As Data.DataRow In foundRowsCancelled

    If cancelledRow.Table.Columns.Contains("RefNum") Then

        If String.IsNullOrEmpty(cancelledRow("RefNum").ToString) Then
            cancelledRow("RefNum") = "None"
        Else
            cancelledRow("RefNum") = "<a target='_blank' href='http://www.yahoo.com'>View</a>"
        End If

    Else
        cancelledRow.Table.Columns.Add("RefNum", GetType(String))
        cancelledRow("RefNum") = "None"
    End If

    If Not cancelledRow.Table.Columns.Contains("ViewLink") Then
        cancelledRow.Table.Columns.Add("ViewLink", GetType(String))
    End If

    If Not String.IsNullOrEmpty(cancelledRow("SystemID").ToString) Then
        cancelledRow("ViewLink") = "test3"
    Else
        cancelledRow("ViewLink") = "test4"
    End If

    cancelledTable.ImportRow(cancelledRow)
Next

dsCancelledData.DataSetName = "CancelledDataSet"
dsCancelledData.Tables(0).TableName = "CancelledTable"
'/second grid




Any help wowuld be apprecaited.
Thanks.
Posted

1 solution

Ok guys,

I got it...phew,
highlighted is the line of code that i was missing.

i added the column before filling the dataset with data but just after i cloned the structure i need.

VB
<pre lang="vb">Dim dataSetResults As DataSet
Dim foundRowsCancelling() As Data.DataRow
Dim foundRowsCancelled() As Data.DataRow

dataSetResults = ExecStoredProcThatReturnsDataSet("Stored_Proc")

'first grid
dsCancellingData = dataSetResults.Clone()
dsCancellingData.Tables(0).Columns.Add("ViewCancellingLink", GetType(String))
foundRowsCancelling = dataSetResults.Tables(0).Select("SystemStatus <> 'F'")

Dim cancellingTable As DataTable = dsCancellingData.Tables(0)

For Each cancellingRow As Data.DataRow In foundRowsCancelling

    If cancellingRow.Table.Columns.Contains("RefNum") Then

        If String.IsNullOrEmpty(cancellingRow("RefNum").ToString) Then
            cancellingRow("RefNum") = "None"
        Else
            cancellingRow("RefNum") = "<a target='_blank' href='http://www.google.com'>View</a>"
        End If
    Else
        cancellingRow.Table.Columns.Add("RefNum", GetType(String))
        cancellingRow("RefNum") = "None"
    End If

    If Not cancellingRow.Table.Columns.Contains("ViewLink") Then
        cancellingRow.Table.Columns.Add("ViewLink", GetType(String))
    End If

    If Not String.IsNullOrEmpty(cancellingRow("SystemID").ToString) Then
        cancellingRow("ViewLink") = "test1"
    Else
        cancellingRow("ViewLink") = "test2"
    End If

    cancellingTable.ImportRow(cancellingRow)
Next

dsCancellingData.DataSetName = "CancellingDataSet"
dsCancellingData.Tables(0).TableName = "CancellingTable"
'/first grid

'second grid
dsCancelledData = dataSetResults.Clone()
dsCancelledData.Tables(0).Columns.Add("ViewCancelledLink", GetType(String))
foundRowsCancelled = dataSetResults.Tables(0).Select("SystemStatus = 'Z'")

Dim cancelledTable As DataTable = dsCancelledData.Tables(0)

For Each cancelledRow As Data.DataRow In foundRowsCancelled

    If cancelledRow.Table.Columns.Contains("RefNum") Then

        If String.IsNullOrEmpty(cancelledRow("RefNum").ToString) Then
            cancelledRow("RefNum") = "None"
        Else
            cancelledRow("RefNum") = "<a target='_blank' href='http://www.yahoo.com'>View</a>"
        End If

    Else
        cancelledRow.Table.Columns.Add("RefNum", GetType(String))
        cancelledRow("RefNum") = "None"
    End If

    If Not cancelledRow.Table.Columns.Contains("ViewLink") Then
        cancelledRow.Table.Columns.Add("ViewLink", GetType(String))
    End If

    If Not String.IsNullOrEmpty(cancelledRow("SystemID").ToString) Then
        cancelledRow("ViewLink") = "test3"
    Else
        cancelledRow("ViewLink") = "test4"
    End If

    cancelledTable.ImportRow(cancelledRow)
Next

dsCancelledData.DataSetName = "CancelledDataSet"
dsCancelledData.Tables(0).TableName = "CancelledTable"
'/second grid


thanks for looking
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900