Home All Groups Group Topic Archive Search About

DataGrid - Edit, Update, Delete

Author
7 Feb 2006 6:26 PM
drakuu
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

Author
7 Feb 2006 7:14 PM
W.G. Ryan - MVP
Does AddressID Accept null values?  I think I remember seeing this before
when I had a null value as opposed to using DBNull.Value
<dra***@gmail.com> wrote in message
Show quote
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
>
Author
9 Feb 2006 8:33 PM
drakuu
It was a BUG in VS2005 Beta 2 version. My code is perfectly fine.

Thanks all for help.

draku

AddThis Social Bookmark Button