Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 23rd, 2003, 10:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,111
Thanks: 0
Thanked 3 Times in 3 Posts
Default Deleting from a table

I'm using an access db and trying to follow along with code for SQL Server.

This is the error message i'm getting:

No value given for one or more required parameters.

Line 65: objConn.Open()
----->Line 66: objCommand.ExecuteNonQuery() <-------
Line 67: objConn.Close()

on line 66.

Sub DBDelDataGrid_Delete(ByVal source As Object, ByVal E As DataGridCommandEventArgs)
        Dim objCommand As OleDbCommand
        Dim strSQLQuery As String

        strSQLQuery = "DELETE FROM zNews WHERE id=" & dgNews.DataKeys(E.Item.ItemIndex) & ";"

        'Response.Write(strSQLQuery)
        'Response.End()

         objCommand = New OleDbCommand(strSQLQuery, objConn)

        objConn.Open()
        objCommand.ExecuteNonQuery()
        objConn.Close()

        ShowDataGrid()
  #2 (permalink)  
Old September 23rd, 2003, 11:45 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

My first thought is that this is not correct:

    E.Item.ItemIndex

By this you are implying that the ID field of your database table is always going to align correctly with the ItemIndex generated by the datagrid for each item (row).

You need to specify where the data for the "ID" column comes from within the datagrid item. Usually you need something like this:

    e.Item.Cells(<index of the ID column>).Text

The index of the ID column will be based on either your original SQL query that got the data for the bind to the data grid (when using AutoGenerateColumns) or the order you placed your columns in the <columns> section of the datagrid HTML.

Peter
  #3 (permalink)  
Old September 23rd, 2003, 12:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,111
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Thanks Peter. Both ended up working after I found my error. I forgot that I changed the id column's name...
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting all the records in a table suthaharmca Beginning VB 6 4 January 2nd, 2008 06:14 PM
Deleting All Record In A Table McDiddy Access VBA 3 January 10th, 2007 09:20 AM
deleting a record from a linked table??? tico31pl Classic ASP Basics 0 May 18th, 2006 09:58 AM
Deleting NULL record in a table dotnet cat SQL Server 2000 5 October 4th, 2005 04:58 PM
Deleting table using Macro in Access sunny76 Access VBA 2 July 5th, 2005 09:18 AM



All times are GMT -4. The time now is 03:16 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.