Insert, Update, Delete through DataGrid

  • Thread starter Thread starter Garry Newman
  • Start date Start date
G

Garry Newman

From what I can gather these commands are automatically
generated throught the OleDbDataAdapter wizard when
working with a one table database and from the MSDN
documnetation the values shown on screen are only a
snapshot of the data stored in the datbase not the actual
data itself. I just can't figure out what code I need in
the click event of my corosponding command buttons to
perform these actions. I presume I need to open, write
and close the database but at this point I'm lost any
help is much appreciated.

Thanks G.N
 
Garry if you set the 'read only' property of the DataDrid
to 'False' then you can use something like...

OleDbDataAdapter1.Update(DataSet1)

from your command button to save any changes you've made
during run-time.

To delete a record you can simply highlight the record
and hit delete on your keyboard likewise to add a record
you can just tab on or mouse click in the last record in
your datagrid which will appear blank and marked with an
* but I don't know how to get this add and delete
function running from command buttons, but I'm sure one
of the experts here will point you in the right direction
when they read your post...

Regards Steve
 
Hello Gary

basically...these are the steps:

1. Fill Datatable using DataAdapter
2. Set DataTable as datasource for grid
3. User makes changes to various rows, maybe adds new row, deletes another,
etc
4. Use update method of DataAdapter to update changes to DataTable




--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
 
Thanks Ibrahim

All these things steps you've highlighted work perfectly
well but all I want is a command button which deletes a
record and one that starts a new record (the typical
controls you would have on an Access form instead of
having to highlight the record and hit delete on keyboard
or click on blank row to activate new record

Thanks G.N
 
ok thanks Steve at least I can get my ammendments to save
now, but I'd really like 'Add' & 'Delete' buttons on my
form instead of having to do it manually...

Thanks GN
 
Hi Garry,

There are a lot of possibilities how to do what your ask.

This is an example of a delete with a button, but it depends how you did
other things if it will work for you. We don't see code of you, do you know.
But this works for me.

\\\
Private Sub btnDelete_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnDelelete.Click
dataset1.Tables(0).Rows(datagrid1.CurrentRowIndex).Delete()
End Sub
///

But basicly I think this is what you are looking for?

Cor
 
Back
Top