Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 23rd, 2003, 10:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
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()
 
Old September 23rd, 2003, 11:45 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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
 
Old September 23rd, 2003, 12:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
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...





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





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