SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 21st, 2002, 11:59 AM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
Strange error deleting a record from mdb table, help.

<i><b>Originally posted by : Salvador Gallego (salvito@hispavista.com)</b></i><br />Hi all, <br /><br />I found problems deleting a Row from an MDB database, this is my datagrid (is just the same i been using): <br /><br /><ASPataGrid id="DBAddDataGrid" runat="server" <br /> Width="100%" <br /> BackColor="white" <br /> BorderColor="black" <br /> ShowFooter="false" <br /> CellPadding=3 <br /> CellSpacing="0" <br /> Font-Name="Verdana" <br /> Font-Size="8pt" <br /> Headerstyle-BackColor="lightblue" <br /> Headerstyle-Font-Size="10pt" <br /> Headerstyle-Font-Style="bold" <br /> OnDeleteCommand="DBAddDataGrid_Delete" <br />> <br /> <Columns> <br /> <asp:ButtonColumn <br /> HeaderText="Delete Item" <br /> ButtonType="PushButton" <br /> Text="Trash It!" <br /> CommandName="Delete" /> ---> "CommandName" added <br /> </Columns> <br /></ASPataGrid> <br /><br />------------------ <br /><br />And here's the procedure which doesn't work to delete a row: <br /><br />------------------ <br /><br /> Sub DBAddDataGrid_Delete(Sender As Object, E As DataGridCommandEventArgs) <br />'<!-- Dim objConnection Declared on top --> <br />'<!-- Dim objCommand Declared on top --> <br /> Dim DeleteCmd As String = "DELETE from tbdownloads where IdF = @Id" <br /> <br /> objCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 11)) <br /> objCommand.Parameters("@Id").Value = DBAddDataGrid.DataKeys(CInt(E.Item.ItemIndex)) <br /> objCommand = New OleDbCommand (DeleteCmd, objConnection) <br /><br /> objConnection.Open() <br /> objCommand.ExecuteNonQuery <br /> objConnection.Close() <br /> ShowDataGrid() <br /> End Sub <br /><br />------------------ <br /><br /><br />The Idea is that I render a field called Id which I use in the Sql query to compare with my autonumber field called IdF and then if it's the same, delete that row... <br /><br />But, of course, it doesn't work, the error I get is:<br /><br />----<br />Object reference not set to an instance of an object. <br />Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br /><br />Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.<br /><br />Source Error: <br /><br /><br />Line 24: Dim DeleteCmd As String = "DELETE from tbdownloads where IdF = @Id"<br />Line 25: <br />Line 26: objCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 11)) <br />Line 27: objCommand.Parameters("@Id").Value = DBAddDataGrid.DataKeys(CInt(E.Item.ItemIndex))<br />Line 28: objCommand = New OleDbCommand (DeleteCmd, objConnection) <br />---- <br /><br />Why? <br /><br />Any Ideas? <br /><br />Thanks!! <br /><br />Salvador Gallego. <br /><br />

Reply With Quote
  #2  
Old October 14th, 2003, 11:30 AM
m_lazor m_lazor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Luxembourg
Posts: 156 m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
So objCommand and the othe connection stuff has been created with CreatObject somewhere else?

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Strange error deleting a record from mdb table, help.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT