ashley
ashley

Reputation: 1038

how to update an existing datatable in vb.net

hope you doing fine. I really need some help. actually I am developing a small application for creating invoices. one thing that I am finding really hard is when you have to edit an invoice. In my application, it generates an invoice number and you fill in the details such as description, qty, unit price and total amount. at first this is saved in the db, printed and shown to the head for approval. if there is any mistake, the user has to come back to the application and makes the changes for the invoice. this is where I am getting stuck. The application can recall the invoice. but once the changes made, I have to save it back to the db and this change can be for a specific record only. for instance,

invoice 001

serial descr qty unitprice total 1 paintx 2 2000 4000 2 painty 3 1000 3000 3 paintz 1 2000 2000

lets say there is a mistake and amendments to be done

serial descr qty unitprice total 1 paintx 2 2000 4000 2 painty 3 1000 3000 3 paintz 2 2000 4000

how am I supposed to make this change ?

any technique or logic I can use?

do I need to use datatable here?

please advise.

Upvotes: 0

Views: 904

Answers (2)

Virender Choudhary
Virender Choudhary

Reputation: 11

    Newfun()'Function for open the connection

    Dim query As String = "update tBL_GageType set GageType = '" & name & "' where GID=" & id
    Dim cmd As New OleDbCommand(query)
    cmd.Connection = New OleDb.OleDbConnection(connectionString)
    cmd.Connection.Open()
    cmd.ExecuteNonQuery()

Upvotes: 1

Ian Atkin
Ian Atkin

Reputation: 6346

Well, you've given no clue as to the database technology/adapter you're using, but it should be something like...

con.Open()
cmd.Connection = con
cmd.CommandText = "UPDATE invoices SET serial = @serial, descr = @descr, qty = @qty ... etc... WHERE invoiceId = @invoiceId"
cmd.Parameters.AddWithValue("@serial", Form.txtSerial.Text)
cmd.Parameters.AddWithValue("@descr", Form.txtDescr.Text)
cmd.Parameters.AddWithValue("@qty", Form.txtQty.Text)
... etc...

cmd.ExecuteNonQuery()

Further reading: MSDN post on updating tables in VB.NET

Upvotes: 1

Related Questions