Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - the ExecuteNonQuery problem()??pls help!!
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

the ExecuteNonQuery problem()??pls help!!

 Post Reply Post Reply
Author
wancherng View Drop Down
Newbie
Newbie
Avatar

Joined: 16 March 2003
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote wancherng Quote  Post ReplyReply Direct Link To This Post Topic: the ExecuteNonQuery problem()??pls help!!
    Posted: 28 March 2003 at 1:29am

i am doing a asp-database programming and i am having the following problem:
when i execute the following code, error appears and the stack trace as the following:

*****code*****
Sub Click_Grid(ByVal Sender as Object, ByVal E as DataGridCommandEventArgs)
If E.CommandSource.CommandName = "Edit" Then
Response.Redirect("./edit.aspx?EmployeeID=" _ & E.Item.Cell(1).Text)
ElseIf E.CommandSource.CommandName = "Delete" Then
Dim DBConn as OleDbConnection
Dim DBDelete As New OleDbCommand
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection("PROVIDER=" _ 
&"Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath(".\Emps.mdb;"))
DBDelete.CommandText ="Delete From Employees Where " _
& "EmployeeID = " _
& E.Item.Cells(1).Text
DBDelete.Connection = DBConn
DBDelete.Connection.Open
DBDelete.ExecuteNonQuery()
DBConn = New OleDbConnection("PROVIDER=" _
& "Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath(".\Emps.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select EmployeeID, LastName, FirstName, " _
& "EmailAddress From Employees " _
& "Order By LastName", DBConn)
DBCommand.Fill(DSPageData, _
"Employees")
dgEmps.DataSource = _
DSPageData.Tables("Employees").DefaultView
dgEmps.DataBind
End If
End Sub

****stack trace*****
[OleDbException (0x80004005): Could not delete from specified tables.]

System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
ASP.Index_aspx.Click_Grid(Object Sender,
DataGridCommandEventArgs E) in
http://localhost/WebApplication3/Index.aspx:66
System.Web.UI.WebControls.DataGrid.OnItemCommand(DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()

*************
it happens also when i wanna update or add new record.
can anybody tell me why i modify the database?
as i know the command.ExecuteNonQuery() method is used to execute Insert,
Update, and delete that do not return any row.
but the VS.Net ide indicates that this method(as integer) returns the number
of rows that are affected..
Why? I don't understand?
can anybody help me?

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 28 March 2003 at 5:34am
just because the ExecuteNonQuery returns a # doesn't mean that you have to do something with it

So whether you do
NumofRowsAffected = DBDelete.ExecuteNonQuery()
or
DBDelete.ExecuteNonQuery()

it'll still execute.... i'd say something is wrong with permissions on the Database or something judging by the error produced of:

"[OleDbException (0x80004005): Could not delete from specified tables.]"

If you want some absolutely killer .NET examples/explainations of using ADO.NET, check out this page, good stuff
Contribute to the working anarchy we fondly call the Internet
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.