Link to home
Start Free TrialLog in
Avatar of b3cf
b3cf

asked on

How to add a blank row to a dataset

Hi

   I have the following code that will generate a dataset. Could someone advice me on how I could add a blank row to it.

Any help is greatly appreciated.

 Dim conBrokerCompanies As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Dim cmdBrokerCompanies As SqlCommand = New SqlCommand("GetBrokerCompanies", conBrokerCompanies)
            cmdBrokerCompanies.CommandType = CommandType.StoredProcedure

            Dim daBrokerCompanies As SqlDataAdapter = New SqlDataAdapter(cmdBrokerCompanies)
            Dim dsBrokerCompanies As DataSet = New DataSet

            conBrokerCompanies.Open()

            daBrokerCompanies.Fill(dsBrokerCompanies, "BrokerCompanies")

            conBrokerCompanies.Close()
            conBrokerCompanies.Dispose()

            Return dsBrokerCompanies
 
ASKER CERTIFIED SOLUTION
Avatar of Nazermohideeen
Nazermohideeen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LordWabbit
LordWabbit

Not sure why you would want a blank record but heres some code to try anways

        Dim myRow As DataRow = dsBrokerCompanies.Tables(0).NewRow()
        For Each eleCol As DataColumn In dsBrokerCompanies.Tables(0).Columns
            Select Case eleCol.DataType.ToString
                Case "System.String"
                    myRow(eleCol.ColumnName) = ""
                Case Else
                    myRow(eleCol.ColumnName) = 0
            End Select
        Next
        dsBrokerCompanies.Tables(0).Rows.Add(myRow)

Unfortuanately theres not much you can do about non string data types (unless they are nullable).  I used the case statement instead of an if in case you need to deal with other datatypes.

Avatar of b3cf

ASKER

Thanks