|
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?
|