How to add a blank row to a dataset

Posted on 2006-04-07
Last Modified: 2012-08-14

   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


            daBrokerCompanies.Fill(dsBrokerCompanies, "BrokerCompanies")


            Return dsBrokerCompanies
Question by:b3cf
    LVL 4

    Accepted Solution

    Dim dr as Datarow
    dr = dsBrokerCompanies.Tables("BrokerCompanies").NewRow()

    LVL 11

    Expert Comment

    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

    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.


    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now