Trying to update a datatable

Tongue TiedI am completely frustrated…  Trying to help a friend.

< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

Here is what I have been trying to do..  I am a noob at visual studio.

 

I am setting up an inventory database using VB as the front end.  I have setup an accounts table, product table. These I can view edit, delete, and ad records to fine.

 

I am trying to make an invoice.  I have set up the following tables:

 

tblInvoice

InvoiceNum

Primary Key

AccountNum

Foreign Key For Accounts table

Date

 

Total

Total cost of items

 

tblInvDetails

Invoice Number

Foreign Key from tblinvoice

QtyOrdered

Number of Items ordered

Item description

From Product table

Item price

From Product Table

Total Cost

QtyOrdered * Item Price

 

So far I have a form that I can get Account information filled in from accounts,  date Picker,  item selector, invoice number.

 

I can pick an item select quantity click a view button to view the following in textbox:

Invoice Num           QtyOrdered         Product                Item Price                  total item cost

 

 

 

 

 

 

 

All is well with that here is where the problem comes.  I want to create a button to add items to tblInvDetails. 

 

Once I figure this out I will work on totaling the Total items cost and, updating the Tblinvoice info and printing an invoice.

 

I can not get past this until I figure out the update.

 

Please help…

 



Answer this question

Trying to update a datatable

  • Jonathan Caves - MSFT

    Hi,

    To update a table in ADO .net you must use a data adapter, supply its UpdateCommand and DeleteCommand. You must call the update statement of the adapter and supply your datatable...

    Search the MSDN docs. for information regarding ado.net...

     

    cheers,

    Paul June A. Domag



  • Young Joo




    DIm MySQLString as String = "UPDATE TableName SET FieldAName= 1, FieldBName= 'MyPC';"
    Dim MyCommand as New OledbCommand
    Me.MyCommand.CommandType = CommandType.Text
    Me.MyCommand.CommandText = MySqlString
    Me.MyCommand.Connection = MyConnection
    MyConnection.Open
           Dim NumberOfRecords as integer = MyCommand.ExecuteNonQuery
    myConnection.Close

     



    edit: the above code will update all records because i have not included the 'where' clause



  • jbtechie

    Hi

    If you're looking for SQL samples, A good source to check is
    http://www.w3schools.com/sql/default.asp

    Dustin.


  • MkJnr

    <quote>To update a table in ADO .net you must use a data adapter,...</quote>

    I would not say 'must'...because I can create a SQL Update string and assign it to a command object and then execute the command without ever going near an adapter.Big Smile

  • Harini K P

    OK how do I do the SQL Update string
  • sasi

    Hi,

    Oops (wrong choice of words), DMan1 is right. You can use Command object to specify update, insert and delete statements. But if your using datatables and datasets I guess its safer to use the adapter...

     

    cheers,

    Paul June A. Domag



  • Trying to update a datatable