Deleting Problem

G

Guest

I have set up a GridView control bound to an SQLDataSource control.
Depending on which option a user selects in a DropDownList Each datasource is
a sethe select command retrieves a list of key/value pairs from a spefied
table. I am using a select query in the form of

SELECT PrimaryKey AS ID, Value AS Description from sometable

So that the gridview fields can always be bound to ID and Description fields
irespective of the table the data is comeing from. This works fine.

I am using TemplateFields in the gridview for the data. In the
ItemTemplates the description fields is bound to a Label control and the ID
field is bound to a hidden copntrol. In the EditItemTemplate i am using a
TestBox control for the description and a hidden control for the ID. I am
also using a similar method with a DetailsView control for inserting items.
I am using the <%# Bind("Description") %> syntax to bind the data to the
controls in the TempalteFields. Viewing, Inserting and Updating all work
fine.

However when i try to delete a record i get the following 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: Must declare the
variable '@ID'.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

The delete query i am using is as follows:
DELETE FROM TableName WHERE (PrimaryKey = @ID)

and i have DeleteParamters section as follows:

<DeleteParameters>
<asp:parameter Name="ID" />
</DeleteParameters>

If i remove the hidden field which is bound to the ID field, from the
ItemTemplate section i don't get the error, but obviously it doesn't delete
the record either. When i run the delete query in visual studio directly it
simply asks me for the value of paramtere @ID and then delete the correct
record.

I am sure i am missing something simple but fundamental but i can't figure
out what is wrong.
 
G

Guest

No I didn't, and that fixed it thanks.

As you may be able to tell, i am still learning.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top