Connecting Tech Pros Worldwide Help | Site Map

Problem with asp.net 2.0

RichardF
Guest
 
Posts: n/a
#1: Nov 18 '05
Not sure if ths is the right place, but I couldn't find a group for
asp.net 2.0 beta.

I am having a problem with updating databases using the data grid. I
have the following code...

<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand="Select * From Customers"
UpdateCommand="UPDATE Customers SET CompanyName =
@CompanyName, Country = @Country, Region = @Region WHERE (CustomerID =
@CustomerID)"
DeleteCommand="DELETE FROM Customers WHERE (CustomerID =
@CustomerID)"

ConnectionString="Server=(local);Trusted_Connectio n=True;Integrated
Security=SSPI;Persist Security Info=True;Database=Northwind"
ProviderName="System.Data.SqlClient">
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="CompanyName" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Region" Type="String" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="CustomerID" Type="String" />
</DeleteParameters>
</asp:SqlDataSource>

After clicking edit, making a change and then clicking update I get
the error...

Must declare the variable '@CustomerID'.

(Same happens when I try to Delete as well)

Any ideas?

RichardF
RichardF
Guest
 
Posts: n/a
#2: Nov 18 '05

re: Problem with asp.net 2.0


Oops, I meant GridView not data grid.

RichardF
Guest
 
Posts: n/a
#3: Nov 18 '05

re: Problem with asp.net 2.0


I assume someone else will hit this problem too, so here is the
solution, directly from the author Bill Evjen. As is common with Beta
products, Microsoft "tweaked" a few things!

Change the Update command to...

UpdateCommand="UPDATE Customers SET CompanyName = @CompanyName,
Country = @Country, Region = @Region WHERE (CustomerID =
@original_CustomerID)

....note the "original_" prefix on the CustomerID parameter.

Closed Thread