Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagridview updates

Status
Not open for further replies.

thromada

MIS
May 10, 2004
30
US
Hi all,

I have a form with a datagridview (dgv) that's bound to its bindingsource, dataset, and table adapter. I'm trying to figure how to programmatically update rows/cells in the dgv with values from either a text box, or a row from another dgv.

First case, for example, in a textbox on the form, you enter "Dogs" and you want to update a cell in the currently selected row in the dgv, this works to a point:
me.bindingsource.current("PetType") = me.textbox1.text
me.bindingsource.endedit()
me.datagridview.update()
me.tableadapter.update(me.dataset.table)

This updates the dgv, but the last line for the tableadapter errors and the update never gets flushed to the table.

Second case, for example, you want to take the selected row in one dgv and update the selected row in a second dgv with the values in the first dgv. Isn't there a way to place the values of the first dgv's selected row into an array, then update the specifically selected row in the second dgv... and then flush it to the table?

Thanks for your help with these elementary data updating questions,
Tom.
 
What is the error you are getting on the update?


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
That last line, the tableadapter.update, stops and says "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." Perhaps it has something to do with the Update command expecting a different "value" than me.dataset.table. So I'm trying to figure how to write code to save either a since "cell" in a row, an entire row, and multiple rows.

BTW, for everyone, do you have a recomendation for a great VB2005 book that deals with databases, datagridviews, etc. that narrows down the plethora of commands and syntax needed for "database" applications?

Regards,
Tom.
 
Ok, I thought that was probably the error you are getting. What you need to do is actually set up a command object and pass it to the TableAdapter's UpdateCommand property. Check out the following link for a good starting point:



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top