Trim Character from ComboBox text with source as Datatable?

Posted on 2006-05-20
Last Modified: 2006-11-18
Im using a datatable as the source of my combobox. Code looks like this:

     With ComboBox1
            .DisplayMember = "Account #"
            .ValueMember = "ID"
            .DataSource = MyDataTable
        End With

I want to trim the first character from all the "Account #"s.  My account numbers look like this S0000000001 , I need to get rid of the S. I have tried variations of Trim and Substring(1, 10) on both the combobox and the datatable with no luck. How can I do this ? Thanks for any help you can provide!

Question by:kasowitz
    LVL 28

    Accepted Solution

    I'm assuming you're doing a select statement on the DB, whether it's in a stored procedure or in the code itself, so you should probably try:

    SELECT SUBSTRING([Account #], 2,11), ID FROM MyDataTable

    This will select the column "Account #" from the table and only return the values from the second digit from the left to the last digit. This assumes that your account numbers are all 11 characters long.

    Author Comment

    How would I implement that ?

    I am doing a select statement on a SQL DB.  "SELECT [Account #] FROM TABLE WHERE [Account #] LIKE 'S%' "   Then using the DataAdapter I am filling the DataTable. From the DataTable I am populating the ComboBox.

    So Im not sure how to do what you just said?

    Author Comment

    Sorry, I didnt realize I could use the SUBSTRING command in the actual SQL Statement.

    SELECT SUBSTRING([Account #], 2,11) as ID FROM TABLE WHERE [Account #] LIKE 'S%'  

    works perfect..thanks :)

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    This video discusses moving either the default database or any database to a new volume.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    732 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

    18 Experts available now in Live!

    Get 1:1 Help Now