can't delete row in connected mode

seco

Well-known member
Joined
Mar 4, 2007
Messages
66
Programming Experience
Beginner
Hi

my scenario is
i get the data by datareader and load it into a datatable by dt.load(dr) and i put this thable in

a dataset and make it a datasource to a bindingsource and bind this bindingsource to the controls

then i execute sql statements to insert and update since im in connected mode
and my problem is
1- i click on add button which ahs code like:

VB.NET:
bs.endedit()
bs.addnew()


then write my data and click on update button which execute update statement successfully !! and

then click on delete button which has code like:


VB.NET:
dim x as string=""
x=ctype(bs.item(bs.position),datarowview).row.item("name",DataRowVersion.Original)
mm.executeNonQuery("delete from mytable where name='" & x &"'")
bs.removeCurrent()


it gives me error message says"There is no Original data to access." and also if i use current

version of the row says "There is no Current data to access." !!!
i need help to delete this row from the database how?

thanks in advance.
 
Hi

my scenario is
i get the data by datareader and load it into a datatable by dt.load(dr) and i put this thable in

a dataset and make it a datasource to a bindingsource and bind this bindingsource to the controls
Sounds a bit of a long winded way of doing it to me!
Something wrong with myTableAdapter.Fill(myDataSet.MyTable) ?

then i execute sql statements to insert and update since im in connected mode
Not the way I'd choose to do it, tbh.. Change the dataset data then call myTableAdapter.Update(myDataSet.MyTable)

and my problem is
1- i click on add button which ahs code like:

VB.NET:
bs.endedit()
bs.addnew()


then write my data and click on update button which execute update statement successfully !! and
Great, so you use tableAdapter.Update() to add a new record...

then click on delete button which has code like:


VB.NET:
dim x as string=""
x=ctype(bs.item(bs.position),datarowview).row.item("name",DataRowVersion.Original)
mm.executeNonQuery("delete from mytable where name='" & x &"'")
bs.removeCurrent()
...so why on earth would you do this long and silly way of deleting a row?

myDataSet.MyTable(0).Delete() 'mark the row deleted
myTableAdapter.Update(myDataSet.MyTable) 'commit the deletion to the db. db row is deleted


Maybe your confusion arises because microsoft chose Update() for the name of the sub. THIS HAS NOTHING TO DO WITH AN SQL UPDATE STATEMENT. Update() is capable of performing insert, update and delete as necessary. Update() should be called Persist() or Syncronise() or SaveToDB()..


it gives me error message says"There is no Original data to access." and also if i use current
Of course, the row is new. It has no original data

version of the row says "There is no Current data to access." !!!
It's probably proposed, ie. not commited to the datatable, so it wouldnt have a current value either

i need help to delete this row from the database how?
Er. Given that that row doesnt even exist in the db (because it is new) i think you might struggle doing that.

In any case, this is completely the wrong way to delete a row when working with datasets. Call Delete() on the row, then Update() on the tableadapter
 
thanks for reply

i get data by datareader(connected mode) and call dt.load(dr) as i mention i know it's silly but i have to ..

any way my problem arise when i update and delete because i depend on the bindingsource item. you say call delete on row directly. ok what about the update statement what will the condition of the update statement be? i must Not rely on original or current of the bindingsource so. what i should depend on?

thanks.
 
thanks for reply

i get data by datareader(connected mode) and call dt.load(dr) as i mention i know it's silly but i have to ..
Why? youre only duplciating exactly what it is that the tableadapter does

{quote]
any way my problem arise when i update and delete because i depend on the bindingsource item. you say call delete on row directly. ok what about the update statement what will the condition of the update statement be? i must Not rely on original or current of the bindingsource so. what i should depend on?
[/QUOTE]
Doing your data access properly would leave you without that headache
 
Back
Top