Delete from C#

T

tbends

I have a simple access database with one table name "Models". When I try to
delete using the following code I keep getting the error: Could not delete
from specified tables. Any help is greatly appreciated, I assume it has
something to do with permissions.

Code:
OleDbConnection dbConn = null;
OleDbCommand dbComm = null;
dbConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\db1.mdb;");
dbComm = new OleDbCommand("Delete * From Models;", dbConn);
dbComm.Connection.Open();
dbComm.ExecuteNonQuery();

Stack Trace:
[OleDbException (0x80004005): Could not delete from specified tables.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
+41

System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult) +174
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
+92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,
Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +66
WHomes.Models.btnDelete_Click(Object sender, ImageClickEventArgs e) in
c:\inetpub\wwwroot\whomes\models.aspx.cs:144
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +109

System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +69
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
 
B

Brendan Reynolds

It is probably a permissions issue, yes. The identity under which ASP.NET
runs on your system will need write permission on the folder containing the
database, and it is unlikely to have such permission on the root folder of
the C: drive.

You'll likely get a more definitive answer in an ASP.NET forum, though.
 
B

Brendan Reynolds

Not in C#, Danny. The back-slash character is an escape character in C#, so
for a literal back-slash character you double it.

--
Brendan Reynolds
Access MVP

Danny J. Lesandrini said:
Is your path correct here ...

dbConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\db1.mdb;");

Shouldn't C:\\db1.mdb really be C:\db1.mdb ?
--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


tbends said:
I have a simple access database with one table name "Models". When I try
to
delete using the following code I keep getting the error: Could not
delete
from specified tables. Any help is greatly appreciated, I assume it has
something to do with permissions.

Code:
OleDbConnection dbConn = null;
OleDbCommand dbComm = null;
dbConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\db1.mdb;");
dbComm = new OleDbCommand("Delete * From Models;", dbConn);
dbComm.Connection.Open();
dbComm.ExecuteNonQuery();

Stack Trace:
[OleDbException (0x80004005): Could not delete from specified tables.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32
hr)
+41

System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult) +174
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&
executeResult)
+92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,
Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +66
WHomes.Models.btnDelete_Click(Object sender, ImageClickEventArgs e) in
c:\inetpub\wwwroot\whomes\models.aspx.cs:144
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
+109

System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +69
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
 

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

Top