• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

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
0
davidrichardson
Asked:
davidrichardson
  • 2
1 Solution
 
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
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now