Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / May 2005

Tip: Looking for answers? Try searching our database.

Gridview Control - unable to edit or delete

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SirBillofLanenet - 25 May 2005 16:52 GMT
I am trying to use the delete function of the Gridview control. I drag the
db table to the ide, add the delete command and parameter. I always get and
exception that the stored procedure expects a parameter that was not passed.
The code follows and you can see the parameter is there. This has been the
same for beta1 and beta 2. It must be me. What am I doing wrong?

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"

EmptyDataText="There are no data records to display." AllowSorting="True">

<Columns>

<asp:CommandField ShowDeleteButton="True" />

<asp:BoundField DataField="evnt_id" HeaderText="evnt_id" ReadOnly="True"
SortExpression="evnt_id" />

<asp:BoundField DataField="evnt_Day_num" HeaderText="evnt_Day_num"
SortExpression="evnt_Day_num" />

<asp:BoundField DataField="evnt_week_num" HeaderText="evnt_week_num"
SortExpression="evnt_week_num" />

<asp:BoundField DataField="evnt_name" HeaderText="evnt_name"
SortExpression="evnt_name" />

<asp:BoundField DataField="evnt_Time" HeaderText="evnt_Time"
SortExpression="evnt_Time" />

<asp:BoundField DataField="evnt_addr" HeaderText="evnt_addr"
SortExpression="evnt_addr" />

<asp:BoundField DataField="evnt_city" HeaderText="evnt_city"
SortExpression="evnt_city" />

<asp:BoundField DataField="evnt_state" HeaderText="evnt_state"
SortExpression="evnt_state" />

<asp:BoundField DataField="evnt_zip" HeaderText="evnt_zip"
SortExpression="evnt_zip" />

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:lonestarlabConnectionString %>"

SelectCommand="SELECT [evnt_id], [evnt_Day_num], [evnt_week_num],
[evnt_name], [evnt_Time], [evnt_addr], [evnt_city], [evnt_state], [evnt_zip]
FROM [events_recurring]"

DeleteCommand="DELETE FROM events_recurring WHERE (evnt_id = @evnt_id)"
DeleteCommandType="Text" ProviderName="System.Data.SqlClient">

<DeleteParameters>

<asp:Parameter Name="original_evnt_id" Type="Int16"/>

</DeleteParameters>

</asp:SqlDataSource>
Steven Cheng[MSFT] - 26 May 2005 10:06 GMT
Hi SirBillofLanenet,

Welcome to MSDN newsgroup.
From your description, you're encountering parameter not passed error when
using the DeleteCommand of SqlDataSource(with gridview) in ASP.NET whidbey,
yes?

As for the problem you mentioned, did those code used to work correctly for
you? Based on my local testing (Whidbey beta2), when using the
DeleteCommand, we need to define the parameter as below:

=================
<asp:SqlDataSource ID="myDS" runat="server" ConnectionString="<%$
ConnectionStrings:BetaTestConnectionString %>"

           DeleteCommand="DELETE FROM tblMain WHERE (ID = @original_ID)"

           SelectCommand="SELECT * FROM [tblMain]">

           <DeleteParameters>

               <asp:Parameter Name="original_ID" Type="Int32" />

           </DeleteParameters>

       </asp:SqlDataSource>

=================

I append "original_" in both the deletecommand and the deleteParameters,
would you also have a try on this? Also, I'm not sure whether this is a
database specific problem, have you tried creating a very simple table(2
columns, 1 pk) and perform the same test?

In addition, for the whidbey issues, we can try posting in www.asp.net 
site's forum since many ASP.NET product team's dev engineers will often
help answer questions there.

Thanks,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

SirBillofLanenet - 27 May 2005 07:18 GMT
Thank you for the welcome, this is my first post to the group. I am not sure
if the code ever worked as programmed in my example. I did stumble on a
solution and what seems to be the cause.
The control will not correctly generate the edit and delete code unless the
table has a primary key defined. The control worked properly once I defined
"evntId" as a primary key. The gridview control will generate the edit and
delete checkboxes and the page works correctly  if the table has a primary
key defined.
I am not sure if that is a bug or a quirk. Since the control will not work
even if you manually add the required parameters, I would think it is a bug.
I have not found this mentioned in any of the documentation.
> Hi SirBillofLanenet,
>
[quoted text clipped - 44 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
SirBillofLanenet - 27 May 2005 17:08 GMT
I have found the problem and as usual it is the loose nut behind the
keyboard. That would be me. One must either use the default
OldValuesParameterFormat of "original_{0}" in the control parameters and the
stored procedure or change the OldValuesParameterFormat property of the
datasource control to {0}.

Mystery solved - no bug or quirk

Thanks for your patience with my novice posts.

> Hi SirBillofLanenet,
>
[quoted text clipped - 44 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.