473,769 Members | 3,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

delete a row from table

for some reason when i delete a row, the row doesn't get deleted from the
acutal data table in SQL server. my code follows
what am i missing?

thanks.

Dim row As DataRow

Try

row = ds.Tables("Test Table").Select( "emp_id='" & txtEmpID.Value & "' and
fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0)

row.Delete()

ds.AcceptChange s()

myAdapter.Updat e(ds)

myAdapter.Fill( ds, "TestTable" )

Catch err As Exception

lblError.Text = err.ToString()

End Try
Nov 18 '05 #1
6 2025
AcceptChanges() is used on a dataset to actually delete deleted rows and
clear status flags. As you call this before calling Update on the adapter,
the Update finds nothing to do.

try:

row.Delete()
myAdapter.Updat e(ds)
ds.AcceptChange s() '* no longer need modification info in dataset

-- bruce (sqlwork.com)

"Mark Kurten" <ma*********@ac ordia.com> wrote in message
news:#f******** ******@TK2MSFTN GP09.phx.gbl...
for some reason when i delete a row, the row doesn't get deleted from the
acutal data table in SQL server. my code follows
what am i missing?

thanks.

Dim row As DataRow

Try

row = ds.Tables("Test Table").Select( "emp_id='" & txtEmpID.Value & "' and
fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0)

row.Delete()

ds.AcceptChange s()

myAdapter.Updat e(ds)

myAdapter.Fill( ds, "TestTable" )

Catch err As Exception

lblError.Text = err.ToString()

End Try

Nov 18 '05 #2
Here is my code: I'm receiving the following error.

Thanks.
Try

row = ds.Tables("Test Table").Select( "emp_id=" & txtEmpID.Value) (0)

row.Delete()

myAdapter.Updat e(ds.Tables("Te stTable"))

ds.AcceptChange s()

Session("ds") = ds

Catch err As Exception

lblError.Text = err.ToString()

End Try

System.InvalidO perationExcepti on: Update requires a valid DeleteCommand when
passed DataRow collection with deleted rows.

"bruce barker" <no***********@ safeco.com> wrote in message
news:u2******** ******@tk2msftn gp13.phx.gbl...
AcceptChanges() is used on a dataset to actually delete deleted rows and
clear status flags. As you call this before calling Update on the adapter,
the Update finds nothing to do.

try:

row.Delete()
myAdapter.Updat e(ds)
ds.AcceptChange s() '* no longer need modification info in dataset

-- bruce (sqlwork.com)

"Mark Kurten" <ma*********@ac ordia.com> wrote in message
news:#f******** ******@TK2MSFTN GP09.phx.gbl...
for some reason when i delete a row, the row doesn't get deleted from the acutal data table in SQL server. my code follows
what am i missing?

thanks.

Dim row As DataRow

Try

row = ds.Tables("Test Table").Select( "emp_id='" & txtEmpID.Value & "' and
fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0)

row.Delete()

ds.AcceptChange s()

myAdapter.Updat e(ds)

myAdapter.Fill( ds, "TestTable" )

Catch err As Exception

lblError.Text = err.ToString()

End Try


Nov 18 '05 #3
Your adapter has no clue how to delete data out of your table unless you
tell it. You have to create a command object to specify the delete sql you
are going to use when a deletion occurs. Then set your
adapters.Delete Command to this command.

dim delCmd as SqlCommand = new SqlCommand("Del ete From myTable where
empid=@emp_id", myConn)
sqlCommand.para meters.add(@emp _id, txtEmpID.Value)

myAdapter.Delet eCommand = delCmd

"Mark Kurten" <ma*********@ac ordia.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Here is my code: I'm receiving the following error.

Thanks.
Try

row = ds.Tables("Test Table").Select( "emp_id=" & txtEmpID.Value) (0)

row.Delete()

myAdapter.Updat e(ds.Tables("Te stTable"))

ds.AcceptChange s()

Session("ds") = ds

Catch err As Exception

lblError.Text = err.ToString()

End Try

System.InvalidO perationExcepti on: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.

"bruce barker" <no***********@ safeco.com> wrote in message
news:u2******** ******@tk2msftn gp13.phx.gbl...
AcceptChanges() is used on a dataset to actually delete deleted rows and
clear status flags. As you call this before calling Update on the adapter,
the Update finds nothing to do.

try:

row.Delete()
myAdapter.Updat e(ds)
ds.AcceptChange s() '* no longer need modification info in dataset

-- bruce (sqlwork.com)

"Mark Kurten" <ma*********@ac ordia.com> wrote in message
news:#f******** ******@TK2MSFTN GP09.phx.gbl...
for some reason when i delete a row, the row doesn't get deleted from

the acutal data table in SQL server. my code follows
what am i missing?

thanks.

Dim row As DataRow

Try

row = ds.Tables("Test Table").Select( "emp_id='" & txtEmpID.Value & "' and fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0)
row.Delete()

ds.AcceptChange s()

myAdapter.Updat e(ds)

myAdapter.Fill( ds, "TestTable" )

Catch err As Exception

lblError.Text = err.ToString()

End Try



Nov 18 '05 #4
I'm getting confused because the code below I have seen in other examples,
but I'm trying to delete records out of a dataset and then do an update..The
code below isn't deleting records out of a dataset, correct? It looks as
though it's deleting data directly from the sql server table.
"Michael Ramey" <raterus@localh ost> wrote in message
news:uk******** ******@TK2MSFTN GP11.phx.gbl...
Your adapter has no clue how to delete data out of your table unless you
tell it. You have to create a command object to specify the delete sql you are going to use when a deletion occurs. Then set your
adapters.Delete Command to this command.

dim delCmd as SqlCommand = new SqlCommand("Del ete From myTable where
empid=@emp_id", myConn)
sqlCommand.para meters.add(@emp _id, txtEmpID.Value)

myAdapter.Delet eCommand = delCmd

"Mark Kurten" <ma*********@ac ordia.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Here is my code: I'm receiving the following error.

Thanks.
Try

row = ds.Tables("Test Table").Select( "emp_id=" & txtEmpID.Value) (0)

row.Delete()

myAdapter.Updat e(ds.Tables("Te stTable"))

ds.AcceptChange s()

Session("ds") = ds

Catch err As Exception

lblError.Text = err.ToString()

End Try

System.InvalidO perationExcepti on: Update requires a valid DeleteCommand

when
passed DataRow collection with deleted rows.

"bruce barker" <no***********@ safeco.com> wrote in message
news:u2******** ******@tk2msftn gp13.phx.gbl...
AcceptChanges() is used on a dataset to actually delete deleted rows and clear status flags. As you call this before calling Update on the adapter, the Update finds nothing to do.

try:

row.Delete()
myAdapter.Updat e(ds)
ds.AcceptChange s() '* no longer need modification info in dataset

-- bruce (sqlwork.com)

"Mark Kurten" <ma*********@ac ordia.com> wrote in message
news:#f******** ******@TK2MSFTN GP09.phx.gbl...
> for some reason when i delete a row, the row doesn't get deleted
from
the
> acutal data table in SQL server. my code follows
> what am i missing?
>
> thanks.
>
> Dim row As DataRow
>
> Try
>
> row = ds.Tables("Test Table").Select( "emp_id='" & txtEmpID.Value & "'

and > fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0) >
> row.Delete()
>
> ds.AcceptChange s()
>
> myAdapter.Updat e(ds)
>
> myAdapter.Fill( ds, "TestTable" )
>
> Catch err As Exception
>
> lblError.Text = err.ToString()
>
> End Try
>
>



Nov 18 '05 #5
Hi Mark,
Thanks for posting in the community!
From your description, you'd like to delete a datarow from a certain
DataSet and then use DataAdapter to update it so as to modify the data in
the database server, yes?
If there is anything I misunderstood, please feel free to let me know.

As for this question, I agree to bruce barker's suggestion that you need to
update DataSet before calling the AcceptChanges method. Because when you
call the DataAdaptor's update mehod to update a DataSet, the adpator will
lookup the DAtaset's record(datarow) 's state, if the state is modified , it
will update the value into the actual database, if state is deleted , it'll
delete the acutal row in database and the AcceptChanges method will clear
all the state flags to "Unchanged" and set the row's value to original
value, that's why you found that your dataset didn't actually update to the
actual database. For more detailed info on the AcceptChanges method, you
may refer to the follwing reference in MSDN:
#DataSet.Accept Changes Method
http://msdn.microsoft.com/library/en...datadatasetcla
ssacceptchanges topic.asp?frame =true

In addtion, as for the later question:
"It looks as though it's deleting data directly from the sql server table."

This is because when the DataAdapter udpate a DataSet, it'll loop through
all the datarows in it's DataTAble and looked up each row's state, if state
is modified or deleted or added, it'll execute the proper sqlstatement to
do data manipulation in the actual database. So the code such as

Dim catDA As SqlDataAdapter = New SqlDataAdapter( "SELECT CategoryID,
CategoryName FROM Categories", nwindConn)
catDA.UpdateCom mand = New SqlCommand("UPD ATE Categories SET CategoryName =
@CategoryName " & _
"WHERE CategoryID = @CategoryID",
nwindConn)
catDA.UpdateCom mand.Parameters .Add("@Category Name", SqlDbType.NVarC har, 15,
"CategoryNa me")

is to specify a certain sql statment for the DataAdaptor's proper
command(Insert, query,delete,up date) so that the DataAdapter is able to do
db maniuplation in the actual database. Also, in some cases, we can use
the CommandBuilder to automatically generate sql statements for a
DataAdapter if the actual database stucture is not very complex. You can
view the following reference in MSDN for more detailed description on
"Automatica lly Generated Commands":
#Automatically Generated Commands
http://msdn.microsoft.com/library/en...maticallygener
atedcommands.as p?frame=true

Also, here is some other tech articles in MSDN on updating database with
DataAdapter and DataSet, I believe they'll also be helpful to you:
#Updating the Database with a DataAdapter and the DataSet
http://msdn.microsoft.com/library/en...tingDatabaseWi
thDataAdapterDa taSet.asp?frame =true

#Introduction to Dataset Updates
http://msdn.microsoft.com/library/en...uctiontodatase
tupdates.asp?fr ame=true

Please check out the preceding suggestions. If you have any questions,
please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6
Hi Mark,
Have you had a chance to check out my suggestion or have you got any ideas
on this issue? If you need any further assistance, please feel free to let
me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8905
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB automatically deletes also all those rows in the child table whose foreign key values are equal to the referenced key value in the parent row. However:
2
11800
by: Bob Ganger | last post by:
Hello, I am working on a project using SQL Server 2000 with a database containing about 10 related tables with a lot of columns containing text. The total current size of the database is about 2 Gig. When I delete data from the database, it takes a lot of system resources and monopolizes the database so that all other query requests are slow as mud! Ideally, I would like to be able to issue delete commands to the database on a...
16
3876
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the table, or perhaps bytes, being updated where the engine just decides, screw it, i'll just make a new one. surfed this group and google, but couldn't find anything. the context: we have some java folk who like to parametize/
8
25076
by: John Baker | last post by:
Hi: Access 2000 W98! I have a table with numerous records in it, and am attempting to delete certain records that have been selected from it. These are selected based on the ID number in a different table. While I am using the tools in Access for query setup, its easier to show it on here using the SQL for the query, which is as follows( the table is ): DELETE .date, .,
3
2102
by: John Rivers | last post by:
Hello, I think this will apply to alot of web applications: users want the ability to delete a record in table x this record is related to records in other tables and those to others in other tables etc. in other words we must use cascade delete to do
9
2797
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like this: id Name Surname pictr0 picrt1 pictr2 pictr3
6
3858
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called "Generations"), and it allows the user to add, edit and delete the various records of the table. "Generations" table has the following fields: "IDPerson", NamePerson", "AgePerson" and "IDParent". A record contains the information about a person (his name, his...
3
3426
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. Filename : search_student.php <?php include("../user_access/user_access_control.php"); include("../Database/database.php"); $searchStudentControl = new Access_user;
4
4862
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a sql DataAdapter (da) da.SelectCommand.CommandText = "Select * from Servertbl1" da.Fill(ds, "tbl1") so far, so good. If I add a row to the datagridview I use the following sqlDataAdapter code to update the server table - which works OK when...
29
5344
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks the delete button selected row wants to delete. My problem is(If i delete the first row, its say undefined and change the value is 0) pls check my program. <%pathdefiner = "../"%> <!--#include file="../connection/connector.asp" -->...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.