Solved

Binding Textboxes. Will they update the database?

Posted on 2004-08-19
3
185 Views
Last Modified: 2010-04-23
Hi there,
I am New At VB.Net.

I have a simple master detail form with some text fields, comboboxes and a datagrid.
I have several dataadapters making up a dataset.
eg.
POHEADER and PODETAIL are the two main tables used here, there are several other lookup tables.
Their DataAdapters are:
SqldaPOHEADER
SqldaPODETAIL

I have a DataSet called:
dsPurchaseOrder1

The dataset joins the two tables on 'PO_PONO'

The form is populating beautifully. The bound fields have all the correct values and the details table is populating with the correct details.

An example of the properties of one of the bound textbox fields is:
(Name) txtPoSuppAddr1
(Tag) DsPurchaseOrder1 - POHEADER.PO_PONO
(Text) DsPurchaseOrder1 - POHEADER.PO_SUPP_ADDR1

Now I want to make some changes on the form and update the database.

Here is the code:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        SqldaPOHEADER.Update(DsPurchaseOrder1)
        SqldaPODETAIL.Update(DsPurchaseOrder1)
        DsPurchaseOrder1.AcceptChanges()
End Sub

Is there more to it than this?
Does VB.Net have this capability or do I have to do some more work to update the database?

Thanks again,
Marnie.
0
Comment
Question by:MarnieHook
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
saleek earned 50 total points
ID: 11839752
Yes, there is more! You have to create the update command associated with the SqldaPOHEADER adapter and then call the Update() method!

Cmd_Update = New SqlCommand 'create command like u would normally

SqldaPOHEADER.UpdateCommand = Cmd_UpDate 'assign command to adapter

Then you build the command (i.e. give it connection, update query etc), then you call


SqldaPOHEADER.Update(DsPurchaseOrder1)

regards,

KS
0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 11839781
Hi there,

If you dragged your data adapters on using server explorer in Visual Studio it should have created the Select, Update, Delete and Insert commands for you then as saleek mentioned you call the repsective command and the dataset you're affecting.

Good luck

BS
0
 

Author Comment

by:MarnieHook
ID: 11889684
Hi Guys,
Thanks for the tips... I already had the update statement set etc. but it turns out that I needed to an EndEdit() on the row in the dataset before it recognised that there were any changes and updated the database.
Wierd. I didn't seee this anywhere in online help... luckily a girl in my training course came up with the solution. Not sure how I would have guessed this one!

            dsOLEPurchaseOrder.Tables("POHEADER").Rows(BindingContext(DsPurchaseOrder1).Position).EndEdit()

Thanks again.
Marnie.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question