Do not "Remove()/RemoveAt()" datarow from daratable, "Delete()" instead.
Study .NET document to find out the difference of Remove() and Delete().
"Kenny Nemchak" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
> sysiad",dbConnection)
> Dim dataSet As New DataSet
> dataAdapter.Fill(dataSet,"sysiad")
>
> '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>")
> mytable.rows.removeAt(i)
> exit for
> end if
> next i
> response.write(mytable.rows.count & "<br>")
>
> 'Dim datasetmod as dataset
> 'datasetmod = dataset.GetChanges()
>
> dataAdapter.update(dataset,"sysiad")
>
> if dataset.HasChanges()
> response.write("Has Changes <br>")
> else
> 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
> response.write("<tr><td>")
> response.write(mydataview(i)("username").tostring)
> response.write("</td><td>")
> response.write(mydataview(i)("computername").tostring)
> response.write("</td></tr>")
> next
> response.write("</table><br>")
> end if
>
> response.write("'" & request.form("username") &"' has been removed
> from the database.")
|