Add Record To Dataset

Posted on 2004-11-11
Last Modified: 2010-04-24
I am using the following code to search for records in a dataset

        Dim i As Int32
        For i = 0 To DsLocation.Tables("tblscanorder").DefaultView.Count - 1
            If Convert.ToString(DsLocation.Tables("tblscanorder").DefaultView.Item(i).Item("salesorder")).EndsWith(TxtAddNew.Text) Then Exit For
        BindingContext(dvorder).Position = i

What i want to be able to do is if the record dosnt exist that add it

Question by:davidrichardson
    LVL 28

    Accepted Solution

           'create new datatable
            dt = New DataTable
            ' Build dt
            Dim col As DataColumn
            col = New DataColumn("Name", GetType(String))

            Dim col1 As DataColumn
            col1 = New DataColumn("Desc", GetType(String))

    'add row

            Dim data(1) As Object 'for adding to datarow

            ' Add row
                data(0) = "AAAA"
                data(1) = "BBBB"

            ' Accept the data.
    LVL 7

    Author Comment

    the code i am using takes you to the next record if it doent exist how do i stop it doing that
    LVL 28

    Expert Comment

    remark the line

       BindingContext(dvorder).Position = i
    LVL 2

    Expert Comment

    >>What i want to be able to do is if the record dosnt exist that add it

    If your primary goal is to add a record if the record already doesn't exists, why don't you use loadDataRow. LoadDataRow seaches your tables based on primary key and adds a record if the record does not exist before.

    You can find at the following link how to use it.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    731 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

    17 Experts available now in Live!

    Get 1:1 Help Now