?
Solved

How to add a blank row to a dataset

Posted on 2006-04-07
3
Medium Priority
?
692 Views
Last Modified: 2012-08-14
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
 
0
Comment
Question by:b3cf
3 Comments
 
LVL 4

Accepted Solution

by:
Nazermohideeen earned 200 total points
ID: 16400457
Dim dr as Datarow
dr = dsBrokerCompanies.Tables("BrokerCompanies").NewRow()
dsBrokerCompanies.Tables("BrokerCompanies").Rows.Add(dr)

NM
0
 
LVL 11

Expert Comment

by:LordWabbit
ID: 16400532
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.

0
 

Author Comment

by:b3cf
ID: 16403027
Thanks
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 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