473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Deleting Problem

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.


Mar 28 '06 #1
2 1266
Do you have the property datakeynames filled in?
"clickon" <cl*****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
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.

Mar 28 '06 #2
No I didn't, and that fixed it thanks.

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

"Maarten" wrote:
Do you have the property datakeynames filled in?
"clickon" <cl*****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
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.


Mar 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: A | last post by:
Hi, I'm trying to solve the 3rd and final case in deleting a node from a binary tree. That is, deleting a node that has two subtrees. If someone out there who knows about this problem as they...
15
by: Rick | last post by:
Hi, Does deleting an object more than one times incur undefined behavior? I think it doesn't but just making sure... thanks Rick
6
by: Matan Nassau | last post by:
Hello. i have a composite which i want to delete. this is a composite which represents a boolean expression (see a previous post of mine with more details at...
4
by: Fughal | last post by:
Hi, I have a big DB2 database and I need this database without any Data in it for testing something. I have made a backup of these db and restore it on a testing system. My Problem is now how...
13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
6
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application...
5
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. ...
51
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
3
by: Kimera.Kimera | last post by:
I'm trying to write a program in VB.net 2003 that basically deletes all files, folders, sub-folders and sub-sub folders (etc). The program is simply for deleting the Windows/Temp folder contents,...
1
by: Kyosuke18 | last post by:
Hi everyone, I have a problem in deleting a data that is connected on the database.. I tried this code but it shows me an error: Run-time error '-2147217900(80040e14)': Syntax error in string in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.