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>
<asparameter Type="String"
Name="PositionName"></asparameter>
<asparameter Type="String"
Name="BLBGTicker"></asparameter>
<asparameter Type="Boolean" Name="Active"></asparameter>
<asparameter Type="int32"
Name="PK_Position_ID"></asparameter>
</UpdateParameters>
</asp:SqlDataSource>
I appreciate any help,
Patrick
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>
<asparameter Type="String"
Name="PositionName"></asparameter>
<asparameter Type="String"
Name="BLBGTicker"></asparameter>
<asparameter Type="Boolean" Name="Active"></asparameter>
<asparameter Type="int32"
Name="PK_Position_ID"></asparameter>
</UpdateParameters>
</asp:SqlDataSource>
I appreciate any help,
Patrick