Print Page | Close Window

the ExecuteNonQuery problem()??pls help!!

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=1424
Printed Date: 29 March 2026 at 3:37pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: the ExecuteNonQuery problem()??pls help!!
Posted By: wancherng
Subject: the ExecuteNonQuery problem()??pls help!!
Date 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?




Replies:
Posted By: MorningZ
Date 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 http://www.4guysfromrolla.com/webtech/chapters/ASPNET/ch06.2.shtml - this page , good stuff

-------------
Contribute to the working anarchy we fondly call the Internet



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net