|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
why can't perform ExecuteNonQuery??
i am doing a asp-database programming and i am having the following problem:<br>when i execute the following code, error appears and the stack trace as the following:<br><br><br>*****code*****<br>Sub Click_Grid(ByVal Sender as Object, ByVal E as DataGridCommandEventArgs)<br> If E.CommandSource.CommandName = "Edit" Then<br> Response.Redirect("./edit.aspx?EmployeeID=" _<br> & E.Item.Cells(1).Text)<br> ElseIf E.CommandSource.CommandName = "Delete" Then<br> Dim DBConn as OleDbConnection<br> Dim DBDelete As New OleDbCommand<br> Dim DBCommand As OleDbDataAdapter<br> Dim DSPageData as New DataSet<br> DBConn = New OleDbConnection("PROVIDER=" _<br> & "Microsoft.Jet.OLEDB.4.0;" _<br> & "DATA SOURCE=" _<br> & Server.MapPath(".Emps.mdb;"))<br> DBDelete.CommandText ="Delete From Employees Where " _<br> & "EmployeeID = " _<br> & E.Item.Cells(1).Text<br> DBDelete.Connection = DBConn<br> DBDelete.Connection.Open<br> DBDelete.ExecuteNonQuery()<br> DBConn = New OleDbConnection("PROVIDER=" _<br> & "Microsoft.Jet.OLEDB.4.0;" _<br> & "DATA SOURCE=" _<br> & Server.MapPath(".Emps.mdb;"))<br> DBCommand = New OleDbDataAdapter _<br> ("Select EmployeeID, LastName, FirstName, " _<br> & "EmailAddress From Employees " _<br> & "Order By LastName", DBConn) <br> DBCommand.Fill(DSPageData, _<br> "Employees")<br> dgEmps.DataSource = _<br> DSPageData.Tables("Employees").DefaultView<br> dgEmps.DataBind<br> End If<br>End Sub<br><br><br>****stack trace*****<br>[OleDbException (0x80004005): Could not delete from specified tables.]<br><br>System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr)<br><br>System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult)<br><br>System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)<br><br>System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult)<br><br>System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method)<br><br>System.Data.OleDb.OleDbCommand.ExecuteNonQuery()<br><br>ASP.Index_aspx.Click_Grid(Object Sender,<br>DataGridCommandEventArgs E) in http://localhost/WebApplication3/Index.aspx:66<br><br>System.Web.UI.WebControls.DataGrid.OnItemCommand(D ataGridCommandEventArgs e)<br><br>System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs e)<br><br>System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)<br><br>System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source, EventArgs e)<br><br>System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)<br><br>System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e)<br> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)<br><br>System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)<br><br>System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)<br><br>System.Web.UI.Page.ProcessRequestMain()<br><br><br>*************<br>it happens also when i wanna update or add new record.<br>can anybody tell me why i modify the database??<br>as i know the command.ExecuteNonQuery() method is used to execute Insert, Update, and delete that do not return any row.<br>but the VS.Net ide indicates that this method(as integer) returns the number of rows that are affected..<br>Why?? I don't understand??<br>can anybody help me??
|
|
#2
|
|||
|
|||
|
This may not exactly what your looking for, but one major issue I just see right off is that your checking for if edit or delete was clicked.<br>Line#2: If E.CommandSource.CommandName = "Edit" Then<br>Response.Redirect("./edit.aspx?EmployeeID=" _<br>& E.Item.Cells(1).Text)<br>In your html, you must specify functions for when the button is clicked, ie.<br><asp:datagrid id="DataGrid1" runat="server" OnDeleteCommand="DataGrid1_Delete" OnEditCommand="DataGrid1_Edit"><br><br>Then in your code you would have the functions:<br><br><C#><br>protected void DataGrid1_Delete(Object sender, DataGridCommandEventArgs E) <br>{ <br> .....<br>}<br>protected void DataGrid1_Edit(Object sender, DataGridCommandEventArgs E)<br>{<br> .....<br>}<br><br>E Being what was clicked..<br>int DeleteID = (int)DataGrid1.DataKeys[(int)E.Item.ItemIndex];<br><br>always use ID when deleteing from DB!<br><br>-Pete <img border="0" src="/forum/emoticons/jumpin.gif" height="31" width="31" alt="jumpin" />
|
|
#3
|
|||
|
|||
|
but trailing the above code, i have the following html:<br><br><ASP
ATAGRID id="dgEmps" runat="server" OnItemCommand="Click_Grid" OnSortCommand="Sort_Grid" AllowSorting="True" AutoGenerateColumns="False" HeaderStyle-Font-Bold="True" HeaderStyle-BackColor="Burlywood" BackColor="Beige" ForeColor="Black" Font-Size="10pt" Font-Name="Trebuchet MS" CellPadding="3" BorderColor="Black" Width="90%" Font-Names="Trebuchet MS"><br> <br><HeaderStyle Font-Bold="True" BackColor="BurlyWood"></HeaderStyle><br><br><Columns><br><br><asp:HyperLinkColumn DataNavigateUrlField="EmployeeID" DataNavigateUrlFormatString="./view.aspx?EmployeeID={0}" DataTextField="EmployeeID" SortExpression="EmployeeID" HeaderText="ID (Click for More Info)"></asp:HyperLinkColumn><br><br><asp:BoundColumn Visible="False" DataField="EmployeeID"></asp:BoundColumn><br><br><asp:BoundColumn DataField="LastName" SortExpression="LastName" HeaderText="Last Name"></asp:BoundColumn><br><br><asp:BoundColumn DataField="FirstName" HeaderText="First Name"></asp:BoundColumn><br><br><asp:HyperLinkColumn DataNavigateUrlField="EmailAddress" DataNavigateUrlFormatString="mailto:{0}" DataTextField="EmailAddress" SortExpression="EmailAddress" HeaderText="Email Address"></asp:HyperLinkColumn><br><br><asp:ButtonColumn Text="Edit" ButtonType="PushButton" HeaderText="Click to Edit" CommandName="Edit"></asp:ButtonColumn><br><br><asp:ButtonColumn Text="Delete" ButtonType="PushButton" HeaderText="Click to Delete" CommandName="Delete"></asp:ButtonColumn><br><br></Columns><br><br></ASP ATAGRID><br><br>which i think is not the problem of the html but the Access database because before i debug, the database is readable and writeable but after i debug it, the database becomes read-only and dun allow me to do any changes to it. And then when i am trying to delete the database , a message says that the database is being used by another program, but actually i am only using the VS.Net to debug it. so, that's my problem and i dun know how to solve it. |
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > why can't perform ExecuteNonQuery?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|