473,404 Members | 2,195 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,404 software developers and data experts.

Can't delete a record from access DB

I have a web-based C# app. I've got a routine to delete a record from a
database. It executes just fine. No exceptions, no errors that I can find,
but it simply doesn't do anything.

It's not a file permissions issue. I can add new records just fine. I can
delete the records from within Access, no problem.

I'm using ODBC (don't ask, it's a limitation of the environment I'm
deploying to). The code is as follows:

string query = "DELETE FROM Comment WHERE CommentID=" +
commentID.ToString();
using (OdbcConnection conn = new OdbcConnection(_connectionString))
{
using(OdbcCommand cmd = new OdbcCommand(query, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
}
}

Am I missing something? Surely I'm just missing something basic. Everything
else in the app works okay. I can read records and add new records just
fine. I haven't tried updates because they're not needed. Any help would be
greatly appreciated. Thanks.

Pete
Apr 8 '06 #1
6 3416

On 8-Apr-2006, "Pete Davis" <pdavis68@[nospam]hotmail.com> wrote:
I have a web-based C# app. I've got a routine to delete a record from a
database. It executes just fine. No exceptions, no errors that I can find,

but it simply doesn't do anything.

It's not a file permissions issue. I can add new records just fine. I can
delete the records from within Access, no problem.

I'm using ODBC (don't ask, it's a limitation of the environment I'm
deploying to). The code is as follows:

string query = "DELETE FROM Comment WHERE CommentID=" +
commentID.ToString();
using (OdbcConnection conn = new OdbcConnection(_connectionString))
{
using(OdbcCommand cmd = new OdbcCommand(query, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
}
}

Am I missing something? Surely I'm just missing something basic.
Everything
else in the app works okay. I can read records and add new records just
fine. I haven't tried updates because they're not needed. Any help would
be
greatly appreciated. Thanks.


Strings in DB need the ' used before and after the variable....

string query = "DELETE FROM Comment WHERE CommentID = '" + "'" +
commentID.ToString();
Apr 8 '06 #2
Pete Davis wrote:
string query = "DELETE FROM Comment WHERE CommentID=" +
commentID.ToString();
[...] Am I missing something? Surely I'm just missing something basic. Everything
else in the app works okay. I can read records and add new records just
fine. I haven't tried updates because they're not needed. Any help would be
greatly appreciated. Thanks.


It is hard to say without knowing your database table structure.
If CommentId column is of char type, try to add single quotes:

string query = "DELETE FROM Comment WHERE CommentID='" + commentID.ToString() + "'";

Or better yet, use parameterized command.
Apr 8 '06 #3
Sorry, CommentID is an int and the CommentID field in the database is an
int. So the resulting string, query, would look like:

DELETE FROM Comment WHERE CommentID=121

There should be no single quotes because CommentID is not a string in code
or in the DB.

Pete
<Bi****@OnTheBoard.com> wrote in message
news:27*******************@tornado.ohiordc.rr.com. ..

On 8-Apr-2006, "Pete Davis" <pdavis68@[nospam]hotmail.com> wrote:
I have a web-based C# app. I've got a routine to delete a record from a
database. It executes just fine. No exceptions, no errors that I can
find,

but it simply doesn't do anything.

It's not a file permissions issue. I can add new records just fine. I can
delete the records from within Access, no problem.

I'm using ODBC (don't ask, it's a limitation of the environment I'm
deploying to). The code is as follows:

string query = "DELETE FROM Comment WHERE CommentID=" +
commentID.ToString();
using (OdbcConnection conn = new OdbcConnection(_connectionString))
{
using(OdbcCommand cmd = new OdbcCommand(query, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
}
}

Am I missing something? Surely I'm just missing something basic.
Everything
else in the app works okay. I can read records and add new records just
fine. I haven't tried updates because they're not needed. Any help would
be
greatly appreciated. Thanks.


Strings in DB need the ' used before and after the variable....

string query = "DELETE FROM Comment WHERE CommentID = '" + "'" +
commentID.ToString();

Apr 8 '06 #4
Please see my response to Bi****@OnTheBoard.com.
"Sericinus hunter" <se*****@flash.net> wrote in message
news:a7*****************@newssvr24.news.prodigy.ne t...
Pete Davis wrote:
string query = "DELETE FROM Comment WHERE CommentID=" +
commentID.ToString();


[...]
Am I missing something? Surely I'm just missing something basic.
Everything else in the app works okay. I can read records and add new
records just fine. I haven't tried updates because they're not needed.
Any help would be greatly appreciated. Thanks.


It is hard to say without knowing your database table structure.
If CommentId column is of char type, try to add single quotes:

string query = "DELETE FROM Comment WHERE CommentID='" +
commentID.ToString() + "'";

Or better yet, use parameterized command.

Apr 8 '06 #5
Pete Davis wrote:
Please see my response to Bi****@OnTheBoard.com.
Does it work if you use parameters?
"Sericinus hunter" <se*****@flash.net> wrote in message
news:a7*****************@newssvr24.news.prodigy.ne t...
Pete Davis wrote:
string query = "DELETE FROM Comment WHERE CommentID=" +
commentID.ToString();

[...]
Am I missing something? Surely I'm just missing something basic.
Everything else in the app works okay. I can read records and add new
records just fine. I haven't tried updates because they're not needed.
Any help would be greatly appreciated. Thanks.

It is hard to say without knowing your database table structure.
If CommentId column is of char type, try to add single quotes:

string query = "DELETE FROM Comment WHERE CommentID='" +
commentID.ToString() + "'";

Or better yet, use parameterized command.


Apr 8 '06 #6
Wow, my bad. I was just beeing a complete knucklehead. The field in the
database got renamed, just slightly, a while back and I just didn't realize
it. Sure wish it had given an error, but I guess based on SQL syntax, it
wasn't technically incorrect. Sorry for wasting your time (both of you
guys). Thanks for the help.

Pete

"Sericinus hunter" <se*****@flash.net> wrote in message
news:Er*****************@newssvr24.news.prodigy.ne t...
Pete Davis wrote:
Please see my response to Bi****@OnTheBoard.com.


Does it work if you use parameters?
"Sericinus hunter" <se*****@flash.net> wrote in message
news:a7*****************@newssvr24.news.prodigy.ne t...
Pete Davis wrote:

string query = "DELETE FROM Comment WHERE CommentID=" +
commentID.ToString();
[...]
Am I missing something? Surely I'm just missing something basic.
Everything else in the app works okay. I can read records and add new
records just fine. I haven't tried updates because they're not needed.
Any help would be greatly appreciated. Thanks.
It is hard to say without knowing your database table structure.
If CommentId column is of char type, try to add single quotes:

string query = "DELETE FROM Comment WHERE CommentID='" +
commentID.ToString() + "'";

Or better yet, use parameterized command.

Apr 8 '06 #7

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

Similar topics

3
by: Maria | last post by:
Is there another way to delete the current record in a subform from the main form, another subform or a sub-subform other than setting focus on a field in the subform and using run command...
3
by: Tim Marshall | last post by:
HI all, Access 2003, Jet back end. Rather than annoy my users in a particular app by having relationships with enforced relational integrity refuse to delete a record with related records, I'm...
4
by: Susan Bricker | last post by:
I have a command button on a form that is supposed to Delete the record being displayed. The record is displayed one to a form. The form is not a Pop-Up nor is it Modal. Tracing the btnDelete...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
6
by: bobdydd | last post by:
Access 2000 Windows XP Hi Everybody I have got a weird one here. I have a large form frmTransactions based on a single table tblTransactions. There are a lot of fields on the form but...
0
by: ApexData | last post by:
I have a single form with 3-Pagetabs. The pagetab I'm working in has a subform with the subform settings AllowEdits = No, AllowAdditions=No, AllowDeletions=YES The subform works fine in...
16
by: MartinR | last post by:
I would like to know the code that i should use to delete a record without the message box saying "You are about to delete a record, are you sure..." poping up. At the moment i am using the...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
2
by: Swinky | last post by:
I have added a delete control to my form with code in the On Click property. The delete works well, but if I cancel the delete action, the record is still deleted. Here's the code: MsgBox...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.