PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
DataGrid - Edit, Update, Delete
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
DataGrid - Edit, Update, Delete
![]() |
DataGrid - Edit, Update, Delete |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hello there,
I have DataGrid with some records and I would like to edit it right in the datagrid using the built in commands. I can't figure out a way to pass to the SQL query the record ID which I'm editing. SELECT: SelectCommand="SELECT ProviderID, AddressID, Address, Address2, City, State, County, Zip FROM ProviderAddress WHERE (ProviderID = @ProviderID)" <SelectParameters> <asp:SessionParameter Name="ProviderID" SessionField="PId" Type="Int32" /> </SelectParameters> the above works fine. DELETE: DeleteCommand="DELETE FROM [ProviderAddress] WHERE ([AddressID] = @AddressID) AND ([ProviderID] = @ProviderID)" <DeleteParameters> <asp:Parameter Name="AddressID" Type="Int32" /> <asp:SessionParameter Name="ProviderID" SessionField="PId" Type="Int32" /> </DeleteParameters> Doesn't do anything. Posts the page back to itself but no record is effected. When I add DefaultValue="xxx" to the parameter then it works so I know that the AddressID parameter is incorrect. UPDATE: UpdateCommand="UPDATE [ProviderAddress] SET [Address] = @Address, [Address2] = @Address2, [City] = @City, [State] = @State, [County] = @County, [Zip] = @Zip WHERE ([AddressID] = @AddressID AND [ProviderID] = @ProviderID)"> <UpdateParameters> <asp:Parameter Name="Address" /> <asp:Parameter Name="Address2" /> <asp:Parameter Name="City" /> <asp:Parameter Name="State" /> <asp:Parameter Name="County" /> <asp:Parameter Name="Zip" /> <asp:Parameter Name="AddressID" /> <asp:SessionParameter Name="ProviderID" SessionField="PId" Type="Int32" /> </UpdateParameters> Doesn't work at all and returns SQL error: Must declare the variable '@AddressID'. Again, if I define the default value for AddressID then works fine. QUESTION: How can I define the @Values (@AddressID) for the edited record? I have the AddressID value displayed in the DataGrid to I should be able to access it. Thanks, draku |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Does AddressID Accept null values? I think I remember seeing this before
when I had a null value as opposed to using DBNull.Value <drakuu@gmail.com> wrote in message news:1139336782.620007.71170@g47g2000cwa.googlegroups.com... > Hello there, > > I have DataGrid with some records and I would like to edit it right in > the datagrid using the built in commands. > I can't figure out a way to pass to the SQL query the record ID which > I'm editing. > SELECT: > SelectCommand="SELECT ProviderID, AddressID, Address, Address2, City, > State, County, Zip FROM ProviderAddress WHERE (ProviderID = > @ProviderID)" > <SelectParameters> > <asp:SessionParameter Name="ProviderID" SessionField="PId" Type="Int32" > /> > </SelectParameters> > the above works fine. > > DELETE: > DeleteCommand="DELETE FROM [ProviderAddress] WHERE ([AddressID] = > @AddressID) AND ([ProviderID] = @ProviderID)" > <DeleteParameters> > <asp:Parameter Name="AddressID" Type="Int32" /> > <asp:SessionParameter Name="ProviderID" SessionField="PId" Type="Int32" > /> > </DeleteParameters> > Doesn't do anything. Posts the page back to itself but no record is > effected. > When I add DefaultValue="xxx" to the parameter then it works so I know > that the AddressID parameter is incorrect. > > UPDATE: > UpdateCommand="UPDATE [ProviderAddress] SET [Address] = @Address, > [Address2] = @Address2, [City] = @City, [State] = @State, [County] = > @County, [Zip] = @Zip WHERE ([AddressID] = @AddressID AND [ProviderID] > = @ProviderID)"> > <UpdateParameters> > <asp:Parameter Name="Address" /> > <asp:Parameter Name="Address2" /> > <asp:Parameter Name="City" /> > <asp:Parameter Name="State" /> > <asp:Parameter Name="County" /> > <asp:Parameter Name="Zip" /> > <asp:Parameter Name="AddressID" /> > <asp:SessionParameter Name="ProviderID" SessionField="PId" Type="Int32" > /> > </UpdateParameters> > Doesn't work at all and returns SQL error: Must declare the variable > '@AddressID'. > Again, if I define the default value for AddressID then works fine. > > QUESTION: How can I define the @Values (@AddressID) for the edited > record? I have the AddressID value displayed in the DataGrid to I > should be able to access it. > > Thanks, > draku > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
It was a BUG in VS2005 Beta 2 version. My code is perfectly fine.
Thanks all for help. draku |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

