 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 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
|
|
|
|

May 8th, 2005, 06:00 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
GridView edit problem
I am following the data chapter in the beta book and I can't get my code to work :
<asp:GridView ID="GridView1" Width=500px
DataSourceID="SqlDataSource1"
CellPadding="3"
Font-Names="arial"
Font-Size="8pt"
HeaderStyle-BackColor="#dcdcdc"
HeaderStyle-Font-Bold="true"
HeaderStyle-ForeColor="#00015E"
FooterStyle-BackColor="#CCCCCC"
SelectedRowStyle-BackColor="#FFFFFF"
PagerStyle-BackColor=Gray
PagerSettings-Mode=NumericFirstLast
BackColor="#0066CC"
Forecolor="white"
PageSize="10"
AllowPaging=true
AllowSorting=true
AutoGenerateColumns=false
DataKeyNames="CompanyID"
EditRowStyle-BackColor=Gold
EditRowStyle-Font-Names="Arial"
EditRowStyle-ForeColor=Black
Runat="server">
<Columns>
<asp:BoundField Visible=false DataField="CompanyID" ReadOnly=true />
<asp:BoundField HeaderText="Company Name" DataField="CompanyName" SortExpression="CompanyName" />
<asp:BoundField HeaderText="Location" DataField="CompanyLocation" SortExpression="CompanyLocation" />
<asp:CheckBoxField HeaderText="Delivery" DataField="Delivery" SortExpression="Delivery" />
<asp:BoundField HeaderText="Established" DataField="DateEstablished" SortExpression="DateEstablished" />
<asp:BoundField HeaderImageUrl="~/Images/globe.jpg" DataField="Country" SortExpression="Country" NullDisplayText="N/A" />
<asp:CommandField ShowEditButton=true ButtonType=Button />
<asp:CommandField ShowDeleteButton=true ButtonType=Button />
</Columns>
</asp:GridView><BR />
<asp:DetailsView ID="DetailsView1"
DataSourceID="SqlDataSource1"
AllowPaging=true
Runat="server">
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat=server
SelectCommand="SELECT * FROM COMPANY"
ProviderName="<%$ ConnectionStrings:ourco.providerName %>"
ConnectionString="<%$ ConnectionStrings:ourco%>"
UpdateCommand="UPDATE Company SET CompanyName = @CompanyName, CompanyLocation = @CompanyLocation,
Delivery = @Delivery, DateEstablished = @DateEstablished, Country = @Country
WHERE CompanyID = @CompanyID"
DeleteCommand="DELETE FROM Company WHERE CompanyID = @CompanyID">
<UpdateParameters>
<asp:Parameter Name="CompanyID" Type=Int32 />
<asp:Parameter Name="CompanyName" Type=String />
<asp:Parameter Name="CompanyLocation" Type=String />
<asp:Parameter Name="Delivery" Type=Boolean />
<asp:Parameter Name="DateEstablished" Type=DateTime />
<asp:Parameter Name="Country" Type=String />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="CompanyID" Type=Int32 />
</DeleteParameters>
</asp:SqlDataSource>
When I try to do an edit on a row I get the error :
Must declare the scalar variable "@CompanyID"
And when I try to delete a row, I don't get an error but nothing happens. Does anybody have any ideas what I am doing wrong?
Cheers,
Mike
|
|

May 9th, 2005, 01:32 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Mike,
Is it working when removing the column CompanyID (Any how you have set as the datakeyname of the gridview, you need'nt have a column and hide it)
Prashant
|
|

July 8th, 2005, 02:58 PM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Mike...
I have encountered the same problem.
Any success in resolving it? - please let me know.
Thanks,
marek
|
|

July 13th, 2005, 01:26 PM
|
|
Wrox Author
|
|
Join Date: Jul 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
There was a build somewhere between beta 1 to beta 2 where the where clause was changed to:
WHERE [CustomerID] = @original_CustomerID
They added the need for the @original_ part instead of just @CustomerID.
HTH, Bill Evjen
Bill Evjen
Wrox Author
Technical Director - Reuters
|
|

November 10th, 2005, 01:51 PM
|
|
Registered User
|
|
Join Date: Nov 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Found this out the hard way (after MUCH cursing and head-banging) .... and now that the release version of 2.o is out... you will have to remove the "original_" bit to make it work again .....
|
|

April 5th, 2006, 11:23 AM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So ...what is the solution here ?
I got the same problem with .net 2.0
Still could not figure out why update/delete does not work
Thanks
|
|

July 8th, 2006, 10:23 PM
|
|
Registered User
|
|
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Okay, I've spend all day with a similar problem. Neither gridview or detailview would work for update or insert.
Ends up I had a field in the SQL database with a space in the name (Phone Number). It was converted to Phone_Number in generated code, or [Phone Number] at places.
I changed the field name to PhoneNumber and all is well now.
Hope this helps.
Ed
|
|

July 9th, 2006, 05:17 AM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
maybee this is off topic. What do you mean by beta book? I have bought the asp.net 2.0 beginner but I dont understand what you mean with the beta book.
Lars
|
|

January 3rd, 2007, 07:59 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
add DataKeyNames="CompanyID" to your <asp:gridview> will solve your problem
|
|
 |