PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET DataGrid - Edit, Update, Delete

Reply

DataGrid - Edit, Update, Delete

 
Thread Tools Rate Thread
Old 07-02-2006, 06:26 PM   #1
drakuu@gmail.com
Guest
 
Posts: n/a
Default DataGrid - Edit, Update, Delete


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

  Reply With Quote
Old 07-02-2006, 07:14 PM   #2
W.G. Ryan - MVP
Guest
 
Posts: n/a
Default Re: DataGrid - Edit, Update, Delete

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
>



  Reply With Quote
Old 09-02-2006, 08:33 PM   #3
drakuu@gmail.com
Guest
 
Posts: n/a
Default Re: DataGrid - Edit, Update, Delete

It was a BUG in VS2005 Beta 2 version. My code is perfectly fine.

Thanks all for help.

draku

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off