How to Update a row, not add?

melegant

Well-known member
Joined
Feb 2, 2003
Messages
52
Location
NY
Ok, so I posted a question the other day and thought of a much easier way to ask it.

If I query a set of records and fill a datatable
Lets say

SELECT * from CUSTOMERS

Now I fill my datatable..

I am updating information against an data file and want to UPDATE anything that is existing with new information.

So I use the find method of the datatable because I have the primary key info..

It looks like I have to set it equal to a datarow. and this is where i get lost..
How do i UPDATE the info and not add a new row?
What is happening is that when i update my database, its ADDING new rows instead of updating the rows..

argh.
 
i am trying to update the datasets table,

which in turn will update my actual database when I call the dataadapters update method.

here is a piece of the code.

Code:
            OLEcmd = New OleDb.OleDbCommand("Select LineIT,model FROM bomacc WHERE model = " & test & "", OLEcn)
            OLEdr = OLEcmd.ExecuteReader

            While OLEdr.Read()
                readcount = readcount + 1
                holdnum = OLEdr.GetInt32(0)
            End While

            OLEdr.Close()
            OLEdr = Nothing

            If readcount = 1 Then
                Dim oledrwnew() As DataRow = OLEdt.Select("LineIt =" & holdnum)
                OLEdrw(0) = oledrwnew(0)

                OLEdrw(0).Item("Notes") = "Access Control"
                OLEdrw(0).Item("Catg") = MyExcel.Cells(partcount, "E").Text
                OLEdrw(0).Item("Mfgr") = "Software House"
                OLEdrw(0).Item("Pnum") = MyExcel.Cells(partcount, "A").Text
                OLEdrw(0).Item("Model") = MyExcel.Cells(partcount, "A").Text
                OLEdrw(0).Item("Description") = MyExcel.Cells(partcount, "C").Text
                OLEdrw(0).Item("Vendor") = 594
                OLEdrw(0).Item("V2") = 0
                OLEdrw(0).Item("V3") = 0
                OLEdrw(0).Item("List") = Convert.ToDecimal(MyExcel.Cells(partcount, "D").Text)
                OLEdrw(0).Item("Upd") = Date.Now
                OLEdrw(0).Item("Ptype") = 1
                readcount = 0
                partcount = partcount + 1
 
Of course i can use a sql statement

But the point is i am building an application that will read data files and update a database (for parts). I need to check for existing parts and UPDATE those rows and ADD any new rows that are not present.
(based off the Model # which is unique)

Based on the code above, it updates the first row that it finds existing, then ADDs the rest of existing records as new...
 
Well, I figured out what the problem was.

A) I ended up using the datasets FIND method.

The trick is, that when you fill a dataadapter, it does not fill the schema..
(argh)
so , you just call DA.Fillschema(datatable, source or mapped)
and whala..find works like a bastage.

thanks
mel
 
Back
Top