Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Manually Add Row at start of Datatable

Posted on 2011-02-21
4
Medium Priority
?
476 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview

610 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