delete with dataadapter

G

Guest

I'm getting there......
I can update using and oledbdataadapter by calling the
dataadapter1.update(rset) command, but i don't know how to call the delete or
insert
give that the key is correct here is what i have for delete so far:
(datagrid delete event sub)
Dim key As String = dgOrders.DataKeys(e.Item.ItemIndex).ToString()
Dim r As dsOrders.hedRow
r = DsOrders1.hed.FindByhedID(key)
OleDbDataAdapter1.Update(DsOrders1) '<---delete??? how?
........ bind, and, ...
(end sub)
dsOrders is a dataset with a table hed,
OleDbDataAdapter1 is the object created with VS.net
thanks
kes
 
M

Miha Markic [MVP C#]

Hi Kurt,

DataAdapter takes actions based on DataRow.RowState.
Thus, if you want to deleta a row, you have to call r.Delete(). This will
make row with RowState.Deleted and adapter will delete it from the database
within its Update method.
 
W

William \(Bill\) Vaughn

Ok, the "Update" method is not really named very well. It really should be
"AddUpdateDelete" or "ApplyChanges". When it's called, ADO.NET walks the
target DataSet/DataTable and checks the RowState for each row. If it's
"Texas", then you're in trouble, but if it's "Added", the InsertCommand is
executed, "Modified", the UpdateCommand is executed, if it's "Deleted" the
DeleteCommand is executed, or if it's "Unchanged" then nothing is done.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
G

Guest

Thank you for answering.
I may require a little patience. I added a r.delete() giving me the following:
Dim key As String = dgOrders.DataKeys(e.Item.ItemIndex).ToString()
Dim r As dsOrders.hedRow
r = DsOrders1.hed.FindByhedID(key)
r.Delete()
OleDbDataAdapter1.Update(DsOrders1)
Call dataBinder()
I'm getting an "Object reference not set to an instance of an object" error
on that line. This is what i tried before and i'm glad i was on the right
track.
Please let me know if more information is needed.
thanks
KES


Miha Markic said:
Hi Kurt,

DataAdapter takes actions based on DataRow.RowState.
Thus, if you want to deleta a row, you have to call r.Delete(). This will
make row with RowState.Deleted and adapter will delete it from the database
within its Update method.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

Kurt Schroeder said:
I'm getting there......
I can update using and oledbdataadapter by calling the
dataadapter1.update(rset) command, but i don't know how to call the delete
or
insert
give that the key is correct here is what i have for delete so far:
(datagrid delete event sub)
Dim key As String = dgOrders.DataKeys(e.Item.ItemIndex).ToString()
Dim r As dsOrders.hedRow
r = DsOrders1.hed.FindByhedID(key)
OleDbDataAdapter1.Update(DsOrders1) '<---delete??? how?
....... bind, and, ...
(end sub)
dsOrders is a dataset with a table hed,
OleDbDataAdapter1 is the object created with VS.net
thanks
kes
 
G

Guest

Thanks,
You explained it well and this puts it together. Please see my attempt to
delete in my response to Miha's answer. (and thank you to you both!!)
kes
 
M

Miha Markic [MVP C#]

Perhaps r is nothing?
Are you sure it has a value (IOW that r references a row)?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

Kurt Schroeder said:
Thank you for answering.
I may require a little patience. I added a r.delete() giving me the
following:
Dim key As String = dgOrders.DataKeys(e.Item.ItemIndex).ToString()
Dim r As dsOrders.hedRow
r = DsOrders1.hed.FindByhedID(key)
r.Delete()
OleDbDataAdapter1.Update(DsOrders1)
Call dataBinder()
I'm getting an "Object reference not set to an instance of an object"
error
on that line. This is what i tried before and i'm glad i was on the right
track.
Please let me know if more information is needed.
thanks
KES


Miha Markic said:
Hi Kurt,

DataAdapter takes actions based on DataRow.RowState.
Thus, if you want to deleta a row, you have to call r.Delete(). This will
make row with RowState.Deleted and adapter will delete it from the
database
within its Update method.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

message
I'm getting there......
I can update using and oledbdataadapter by calling the
dataadapter1.update(rset) command, but i don't know how to call the
delete
or
insert
give that the key is correct here is what i have for delete so far:
(datagrid delete event sub)
Dim key As String =
dgOrders.DataKeys(e.Item.ItemIndex).ToString()
Dim r As dsOrders.hedRow
r = DsOrders1.hed.FindByhedID(key)
OleDbDataAdapter1.Update(DsOrders1) '<---delete??? how?
....... bind, and, ...
(end sub)
dsOrders is a dataset with a table hed,
OleDbDataAdapter1 is the object created with VS.net
thanks
kes
 
C

Cor Ligthert

Kurt,

Will you please be more precise in your messages, in what types you are
using.

You use now the command.
Dataadapter1.update(rset) what let me think that you have created a kind of
recordset, moreover because you where using that as well in a previous
message with the datareader where you was as well talking about a recordset.

Did you create a recordset using a dataset and want to update that?.

When I look in your code I see that you have a used DSOrders, so it can be
as well a dataset. When it is a recordset, than even does it not work with
the rowstate "Washington"


To update of a dataset you can see this page.

http://msdn.microsoft.com/library/d...mdatacommondbdataadapterclassupdatetopic2.asp
..

Cor
 
G

Guest

thank's again.
I'm still new to this.
I added a Response.Write(key) and it comes up with the correct key value.
but agan when i reference r.hedid, the key field, it errors out) I'm sure
i'm missing something.
thanks
kes

Miha Markic said:
Perhaps r is nothing?
Are you sure it has a value (IOW that r references a row)?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

Kurt Schroeder said:
Thank you for answering.
I may require a little patience. I added a r.delete() giving me the
following:
Dim key As String = dgOrders.DataKeys(e.Item.ItemIndex).ToString()
Dim r As dsOrders.hedRow
r = DsOrders1.hed.FindByhedID(key)
r.Delete()
OleDbDataAdapter1.Update(DsOrders1)
Call dataBinder()
I'm getting an "Object reference not set to an instance of an object"
error
on that line. This is what i tried before and i'm glad i was on the right
track.
Please let me know if more information is needed.
thanks
KES


Miha Markic said:
Hi Kurt,

DataAdapter takes actions based on DataRow.RowState.
Thus, if you want to deleta a row, you have to call r.Delete(). This will
make row with RowState.Deleted and adapter will delete it from the
database
within its Update method.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

message
I'm getting there......
I can update using and oledbdataadapter by calling the
dataadapter1.update(rset) command, but i don't know how to call the
delete
or
insert
give that the key is correct here is what i have for delete so far:
(datagrid delete event sub)
Dim key As String =
dgOrders.DataKeys(e.Item.ItemIndex).ToString()
Dim r As dsOrders.hedRow
r = DsOrders1.hed.FindByhedID(key)
OleDbDataAdapter1.Update(DsOrders1) '<---delete??? how?
....... bind, and, ...
(end sub)
dsOrders is a dataset with a table hed,
OleDbDataAdapter1 is the object created with VS.net
thanks
kes
 
G

Guest

thanks for answering. I still get my terms mixed up and the dataset/recordset
confused.
dsOrders1 is a dataset filled on initial load in a subroutine
with
OleDbDataAdapter1.Fill(DsOrders1)
dgOrders.DataBind()
it is an instance(?) of dsOrders.xsd.
thanks
kes
 
C

Cor Ligthert

Kurt,

Are you sure you have really still that dataset.

I ask this because you are probably using a webapplication.

To keep the dataset you have to do some extra things. (A webform is not
persistent).

Cor
 
G

Guest

i think you are right, but i'm still can't see where. The object i use to
access this is a datagrid and it's viewstate is true. To test i created a
selected sub to highlight an item
Private Sub dgOrders_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgOrders.ItemCommand
dgOrders.SelectedIndex = e.Item.ItemIndex

End Sub
it works, but i may be missing what you are trying to say to me.
thanks
kes
 
G

Guest

OK! got it to work! Thanks for your help. I needed to refill the record set
on each post back. OleDbDataAdapter1.Fill(DsOrders1). I think there should
be a way to just keep the recordset without refilling each time. is this how
it is done?
thanks
kes
 
C

Cor Ligthert

Kurt,
OK! got it to work! Thanks for your help. I needed to refill the record
set
on each post back. OleDbDataAdapter1.Fill(DsOrders1). I think there
should
be a way to just keep the recordset without refilling each time. is this
how
it is done?

I don't know it for a recordset.

However for with a dataset I made today for somebody else a sample about
paging.
It fits probably you as well. I create in that the dataset, where I make it
you can use your fill.

It is in this message

http://groups-beta.google.com/group/microsoft.public.dotnet.languages.vb/msg/ba2eb586c8f0da0a

I hope this helps a little bit?

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

Top