473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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("TestTable").Select("emp_id='" & txtEmpID.Value & "' and
fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0)

row.Delete()

ds.AcceptChanges()

myAdapter.Update(ds)

myAdapter.Fill(ds, "TestTable")

Catch err As Exception

lblError.Text = err.ToString()

End Try
Nov 18 '05 #1
6 2007
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.Update(ds)
ds.AcceptChanges() '* no longer need modification info in dataset

-- bruce (sqlwork.com)

"Mark Kurten" <ma*********@acordia.com> wrote in message
news:#f**************@TK2MSFTNGP09.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("TestTable").Select("emp_id='" & txtEmpID.Value & "' and
fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0)

row.Delete()

ds.AcceptChanges()

myAdapter.Update(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("TestTable").Select("emp_id=" & txtEmpID.Value)(0)

row.Delete()

myAdapter.Update(ds.Tables("TestTable"))

ds.AcceptChanges()

Session("ds") = ds

Catch err As Exception

lblError.Text = err.ToString()

End Try

System.InvalidOperationException: Update requires a valid DeleteCommand when
passed DataRow collection with deleted rows.

"bruce barker" <no***********@safeco.com> wrote in message
news:u2**************@tk2msftngp13.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.Update(ds)
ds.AcceptChanges() '* no longer need modification info in dataset

-- bruce (sqlwork.com)

"Mark Kurten" <ma*********@acordia.com> wrote in message
news:#f**************@TK2MSFTNGP09.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("TestTable").Select("emp_id='" & txtEmpID.Value & "' and
fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0)

row.Delete()

ds.AcceptChanges()

myAdapter.Update(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.DeleteCommand to this command.

dim delCmd as SqlCommand = new SqlCommand("Delete From myTable where
empid=@emp_id", myConn)
sqlCommand.parameters.add(@emp_id, txtEmpID.Value)

myAdapter.DeleteCommand = delCmd

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

Thanks.
Try

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

row.Delete()

myAdapter.Update(ds.Tables("TestTable"))

ds.AcceptChanges()

Session("ds") = ds

Catch err As Exception

lblError.Text = err.ToString()

End Try

System.InvalidOperationException: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.

"bruce barker" <no***********@safeco.com> wrote in message
news:u2**************@tk2msftngp13.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.Update(ds)
ds.AcceptChanges() '* no longer need modification info in dataset

-- bruce (sqlwork.com)

"Mark Kurten" <ma*********@acordia.com> wrote in message
news:#f**************@TK2MSFTNGP09.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("TestTable").Select("emp_id='" & txtEmpID.Value & "' and fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0)
row.Delete()

ds.AcceptChanges()

myAdapter.Update(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@localhost> wrote in message
news:uk**************@TK2MSFTNGP11.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.DeleteCommand to this command.

dim delCmd as SqlCommand = new SqlCommand("Delete From myTable where
empid=@emp_id", myConn)
sqlCommand.parameters.add(@emp_id, txtEmpID.Value)

myAdapter.DeleteCommand = delCmd

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

Thanks.
Try

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

row.Delete()

myAdapter.Update(ds.Tables("TestTable"))

ds.AcceptChanges()

Session("ds") = ds

Catch err As Exception

lblError.Text = err.ToString()

End Try

System.InvalidOperationException: Update requires a valid DeleteCommand

when
passed DataRow collection with deleted rows.

"bruce barker" <no***********@safeco.com> wrote in message
news:u2**************@tk2msftngp13.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.Update(ds)
ds.AcceptChanges() '* no longer need modification info in dataset

-- bruce (sqlwork.com)

"Mark Kurten" <ma*********@acordia.com> wrote in message
news:#f**************@TK2MSFTNGP09.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("TestTable").Select("emp_id='" & txtEmpID.Value & "'

and > fname='" & txtFName.Value & "' and lname='" & txtLName.Value & "' ")(0) >
> row.Delete()
>
> ds.AcceptChanges()
>
> myAdapter.Update(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.AcceptChanges Method
http://msdn.microsoft.com/library/en...datadatasetcla
ssacceptchangestopic.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.UpdateCommand = New SqlCommand("UPDATE Categories SET CategoryName =
@CategoryName " & _
"WHERE CategoryID = @CategoryID",
nwindConn)
catDA.UpdateCommand.Parameters.Add("@CategoryName" , SqlDbType.NVarChar, 15,
"CategoryName")

is to specify a certain sql statment for the DataAdaptor's proper
command(Insert,query,delete,update) 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
"Automatically Generated Commands":
#Automatically Generated Commands
http://msdn.microsoft.com/library/en...maticallygener
atedcommands.asp?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
thDataAdapterDataSet.asp?frame=true

#Introduction to Dataset Updates
http://msdn.microsoft.com/library/en...uctiontodatase
tupdates.asp?frame=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
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...
2
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...
16
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...
8
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...
3
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...
9
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...
6
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...
3
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. ...
4
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...
29
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.