?
Solved

Manually Add Row at start of Datatable

Posted on 2011-02-21
4
Medium Priority
?
471 Views
Last Modified: 2012-06-27
I have a combobox on a form that I am filling by setting the Datasource Property. I want to be able to add a row to the start of the Datatable to display at the top of the combobox that has a 0 Value but instructs the user to select an Option ie: Select Customer....

I have managed to add a row to the datatable, but I don't know how to index it as the first row.

Thanks
Dim sCustomers As String = "SELECT * FROM tCustomers"
        Dim daCustomers As New SqlClient.SqlDataAdapter(sCustomers, myConn.sqlConn)
        daCustomers.Fill(dsCustomers, "dtCustomers")

        Dim newCustomersRow As DataRow = dsCustomers.Tables("dtCustomers").NewRow()
        newCustomersRow("ID") = "0"
        newCustomersRow("sName") = "Select Customer...."
        dsCustomers.Tables("dtCustomers").Rows.Add(newCustomersRow)

        cboCustomerName.DataSource = dsCustomers.Tables("dtCustomers")
        cboCustomerName.DisplayMember = "sName"
        cboCustomerName.ValueMember = "ID"

Open in new window

0
Comment
Question by:mgordon-spi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 2000 total points
ID: 34947644
0
 
LVL 6

Expert Comment

by:AkAlan
ID: 34947715
Here is an example of how I do what you are asking. It is a function of the DropDownList more than doing it with your dataset. the AppendDataBoundItems is the important option to remember.

<asp:DropDownList ID="ddlSite" runat="server" Width="145px"  AppendDataBoundItems="true"  DataSourceID="sdsSite"
        DataTextField="SiteName" DataValueField="SiteID">
        <asp:ListItem Value="0">--Site--</asp:ListItem>
    </asp:DropDownList>
0
 

Author Comment

by:mgordon-spi
ID: 34947883
This is a vb form not a webpage. I can append quite easily in asp.net, but I am at a loss of how to do it with an Application
0
 

Author Comment

by:mgordon-spi
ID: 34947896
rawinnlnx9 that link did exactly what I needed it to.. Thank you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

752 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