Programically update a colum in a datagrid

G

Guest

I have a datagrid with a DataAdapter as the DataSource. The user fills in
their data for 3 columns and I want to programically add a value to the 4th
(invisible) column (employee number). That way when the user saves the data I
can use the data already in the datagrid.

Typically the user will add several rows before the DataSet.HasChanges is
called and the DataAdapter.Update(AllChanges) is called. I want to add an
employee number to each record programmically within this save routine. Yeah,
stupid, but I need the answer to complet this project.

I really don't want to use a DataReader and write the SQL UPDATE or INSERT
commands, this needs to be done for about 30 tables and I don't have the time.
 
C

Cor Ligthert [MVP]

Jim,
I have a datagrid with a DataAdapter as the DataSource. The user fills in
their data for 3 columns and I want to programically add a value to the
4th
(invisible) column (employee number). That way when the user saves the
data I
can use the data already in the datagrid.

Typically the user will add several rows before the DataSet.HasChanges is
called and the DataAdapter.Update(AllChanges) is called. I want to add an
employee number to each record programmically within this save routine.
Yeah,
stupid, but I need the answer to complet this project.

I really don't want to use a DataReader and write the SQL UPDATE or INSERT
commands, this needs to be done for about 30 tables and I don't have the
time.
--

And why can you not make this?

(Especially the text acceptchanges is interesting by the way, normally you
don't need that with a dataadapter, so show some code around that)

I hope this helps,

Cor
 
G

Guest

Huh?

I have a dataset with a row that has been updated or inserted by the user
via a datagrid. I need to insert a value in one of the grids columns for each
row prior to saving the data. I am using ds.HasChanges to validate that
changes have occured and da.Update(Changes) to update the records. Below is
the update code:

Dim AllChanges As DataSet

If dsAnesthesia.HasChanges() = True Then
AllChanges = dsAnesthesia.GetChanges()
daAnesthesia.Update(AllChanges)
End If

All I want to do is programically insert a value into a bound datagrid
column prior to saving the row. How do I programically access a specific
column whenever the user is either adding or updating a record using a
datagrid.
 
C

Cor Ligthert [MVP]

Jim,

Sorry, I misreaded haschanges for acceptchanges.

However why not just before you update loop through the datatable.
If dsAnesthesia.HasChanges() = True Then
AllChanges = dsAnesthesia.GetChanges()
for each dr in AllChanges.Tables(0).rows
'assuming it is one table
dr.item(3) = "whatever"
next
daAnesthesia.Update(AllChanges)
dsAnestesia.acceptchanges
'with getchanges you get a copy therefore the update changes will not be
done by the dataadapter

To hide the column in a simple way you can use this sample.

http://www.windowsformsdatagridhelp.com/default.aspx?ID=76a81eb8-ea2d-48f4-99c3-a3539697edbd

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top