Add Record To Dataset

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
        Next
        BindingContext(dvorder).Position = i
        DsLocation_PositionChanged()

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

Thanks
LVL 7
davidrichardsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

        Dim col1 As DataColumn
        col1 = New DataColumn("Desc", GetType(String))
        dt.Columns.Add(col1)


'add row

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

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

        ' Accept the data.
        dt.AcceptChanges()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
davidrichardsonAuthor Commented:
the code i am using takes you to the next record if it doent exist how do i stop it doing that
0
iboutchkineCommented:
remark the line

   BindingContext(dvorder).Position = i
0
karthikeyanTPCommented:
>>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.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatatableclassloaddatarowtopic.asp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.