@ID' expects parameter @ID, which was not supplied

@ID' expects parameter @ID, which was not supplied

Post by vbnetrooki » Fri, 29 Jul 2005 22:20:29



Hi all!!!

I get this error:



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.

Exception Details: System.Data.SqlClient.SqlException: Prepared


***************************************

What I'm trying to do is have a datagrid that let's me see the last 5
entries in my database table. And I would like to have a delete
linkbutton on the datagrid that permits me to delete any row in the
grid which in turn would delete it from the database table. My problem
is that I found the code from a book I bought but one parameter gives

cope with it. If anyone could help me determine what the problem is I
would appreciate. HEre is my code from the aspx.vb page:
**************************
(GLOBAL VARIABLES):
Dim cnn As SqlConnection = SqlConnection1
Dim mds As DataSet = New DataSet
Dim mda As SqlDataAdapter = New SqlDataAdapter

(INSIDE THE CODE):
Private Sub btnsee_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnsee.Click
        Datagrid2.Visible = True
        Dim cmdselect As SqlCommand = SqlConnection1.CreateCommand()
        cmdselect.CommandType = CommandType.Text
        cmdselect.CommandText = "SELECT TOP 5 Title,First_Name,
Last_Name, Address, City, Province, PostalCode, Reason, Explanation,
Issue, InsertedAt FROM PubReturn ORDER BY InsertedAt DESC  "
        Dim cmdDelete As SqlCommand = SqlConnection1.CreateCommand
        cmdDelete.CommandType = CommandType.Text



DataRowVersion.Original
        'Set up the DataAdapter and fill the DataSet
        mda.SelectCommand = cmdselect
        mda.SelectCommand = cmdDelete
        'Get the current data from the database
        mda.Fill(mds, "PubReturn")
        LoadData()
End Sub

    Private Sub LoadData()
        'Bind the data to the Datagrid
        Datagrid2.DataSource = mds
        Datagrid2.DataMember = "PubReturn"
        Datagrid2.DataBind()
    End Sub

    Private Sub Datagrid2_CancelCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
Datagrid2.CancelCommand
        'Cancel editing
        Datagrid2.EditItemIndex = -1
        LoadData()
    End Sub

    Private Sub Datagrid2_DeleteCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
Datagrid2.DeleteCommand
        'Find the specified row and delete it
        Dim strID As String = Datagrid2.DataKeys(e.Item.ItemIndex)
        Dim dr As DataRow
        Dim i As Integer
        For i = 0 To mds.Tables("PubReturn").Rows.Count - 1
            dr = mds.Tables("PubReturn").Rows(i)
            If dr(0) = strID Then
                Exit For
            End If
        Next
        'Update the database
        mda.Update(mds, "PubReturn")
        'And bind the data to the UI
        LoadData()

************************************************
ID is a key column in my db table. It is a integer with identity=yes,
seed=1 increment=1.

How come am I getting this error???

Thanks again for all the help guys!!

JMT