GridView not updating in asp.net 2.0

N

n1patrick

Hello all,

I'm stuck on something.I have a little page that I want to update a
table in my sql database so I thought a GridView would be the quickest
way to implement this (wrong!). The grid displays the data fine but the
updates aren't working. After looking at SQL Profiler I can see that it
is not passing through the new values.

For example if I try to update the PositionName textbox from
'Microsoft' to 'BLAHBLAH' in Profiler it shows the following:
exec sp_executesql N'UPDATE [tPositions]
SET [PositionName] = @PositionName, [BLBGTicker] = @BLBGTicker,
[Active] = @Active
WHERE ([PK_Position_ID] = @PK_Position_ID)', N'@PositionName
nvarchar(9),@BLBGTicker nvarchar(4),@Active bit,@PK_Position_ID int',
@PositionName = N'Microsoft', @BLBGTicker = N'MSFT', @Active = 1,
@PK_Position_ID = 2

You can see the the PositionName is still Microsoft.

Here is the code:

<asp:GridView ID="gdvPositions" Runat="server"
DataSourceID="SqlDataSource1"
DataKeyNames="PK_Position_ID" AutoGenerateColumns="False"
AllowSorting="true"
AutoGenerateEditButton="true">
<Columns>
<asp:BoundField HeaderText="Position Name"
DataField="PositionName"
SortExpression="PositionName"></asp:BoundField>
<asp:BoundField HeaderText="BLBG Ticker" DataField="BLBGTicker"
SortExpression="BLBGTicker"></asp:BoundField>
<asp:CheckBoxField HeaderText="Active" DataField="Active"
SortExpression="Active"></asp:CheckBoxField>
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand="SELECT [PK_Position_ID], [PositionName],
[BLBGTicker], [Active] FROM [tPositions]"
ConnectionString="<%$ ConnectionStrings:constring %>"
DataSourceMode="DataSet"
ConflictDetection="CompareAllValues"

UpdateCommand="UPDATE [tPositions]
SET [PositionName] = @PositionName, [BLBGTicker] = @BLBGTicker,
[Active] = @Active
WHERE ([PK_Position_ID] = @PK_Position_ID)">

<UpdateParameters>
<asp:parameter Type="String"
Name="PositionName"></asp:parameter>
<asp:parameter Type="String"
Name="BLBGTicker"></asp:parameter>
<asp:parameter Type="Boolean" Name="Active"></asp:parameter>
<asp:parameter Type="int32"
Name="PK_Position_ID"></asp:parameter>
</UpdateParameters>
</asp:SqlDataSource>

I appreciate any help,
Patrick
 
N

n1patrick

I worked out that when I set the conflict detection to compare all
values it just passes the old values, not the new ones. When I remove
this porperty it works. I'm not really sure why it prevented my code
from running but at least it is working.

ConflictDetection="CompareAllValues"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top