473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

GridView not updating in asp.net 2.0

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

Dec 22 '06 #1
1 3119
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"

Dec 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass...
3
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
5
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying...
0
by: Michael Kellogg | last post by:
I have a problem wherein a query that updates a GridView doesn't seem to really stay in sync with a label I have above the GridView. I have a GridView object that I'm updating with information...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Hi, I have a gridview which I added a <asp:CommandField EditText="E" CancelText="C" UpdateText="U" ButtonType="Link" ShowEditButton="True" /> my gridview looks like this <asp:GridView...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: steve | last post by:
I have been fighting with trying to update a GridView for a while. I don't want to use the "built-in" way to do it because I am using business layer methods for updating and deleteing and I don't...
0
by: BizWeb | last post by:
Hi, i am new to ASP.NET. I have write a very simple code to try the updating of the GridView but it is not updating the data. Below is the simple code that i have use. <%@ Page Language="vb"...
2
by: xMetalDetectorx | last post by:
Hi Everyone, I have a very simple web app that uses .Net 2.0 login control to authenticate users and allow access to an "admin" folder. Inside that admin folder I have one page that has a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.