Update Method Not Updating Database


Kenny Nemchak

I'm new to ASP.NET so I'm probably just missing a simple statement.
The code runs fine with no errors, but the update method does not
update the SQL database.
I open the database, fill the dataset, find a row, delete the row and
attempt to update the database.
All but the update works.
I have 2 asp.net books and have tried their ways…both different.
I've tried to read everything on msdn.microsoft and tried their ways.
The one books says the update method does everything for you…the other
book says you need to set a deletecommand…which I did and still no
update…you can see the deletecommand commented out below.
I also tried creating a second dataset and inserting the changes but
when I use this dataset with update, it errors out and says it's
null…those lines are commented out below.
You can see I put in a couple lines to show the dataset and any
changes…it shows no changes…???
However, when I write out the dataset after deleting the row, the
deleted row is missing.

Dim dbConnection As new SqlConnection("server='xsql'; user id='****';
password='****'; database='cconnect'")
Dim dataAdapter As New SqlDataAdapter("SELECT * FROM
Dim dataSet As New DataSet

'Dim cmd as new SqlCommand("DELETE FROM sysiad",dbConnection)
'dataAdapter.deleteCommand = cmd

Dim mytable as DataTable = dataset.tables("sysiad")
Dim i as integer = 0
response.write(mytable.rows.count & "<br>")
for i = 0 to (mytable.rows.count - 1)
response.write("'" & mytable.rows(i)(0) & "'" & mytable.rows(i)(1)
& "<br>")
if trim(mytable.rows(i)(0)) = request.form("username") then
response.write("stop <br>")
exit for
end if
next i
response.write(mytable.rows.count & "<br>")

'Dim datasetmod as dataset
'datasetmod = dataset.GetChanges()


if dataset.HasChanges()
response.write("Has Changes <br>")
response.write("Has No Changes <br>")
end if

Dim mydataview as dataview
mydataview = new dataview(dataset.tables("sysiad"))
If mydataview.count <> 0 then
response.write("<table border=1>")
for i = 0 to mydataview.count - 1
end if

response.write("'" & request.form("username") &"' has been removed
from the database.")

Norman Yuan

Do not "Remove()/RemoveAt()" datarow from daratable, "Delete()" instead.
Study .NET document to find out the difference of Remove() and Delete().

Kenny Nemchak

Norman Yuan said:
Do not "Remove()/RemoveAt()" datarow from daratable, "Delete()" instead.
Study .NET document to find out the difference of Remove() and Delete().

That was it...thanks.

MSDN says "Remove()/RemoveAt()" is the same as "Delete()" plus
So I changed RemoveAt to Delete AND AcceptChanges...it didn't
work...meaning the database appeared not to be updated.
So I removed the AcceptChanges and it works great.
I had to uncomment my deletecommand to make it work.

I have another question...what is Remove()/RemoveAt() used for?
Display only? You don't use it if you intend to update the source
When would you use the AcceptChanges...after updating the database?

Thanks again.

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