473,395 Members | 1,571 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,395 software developers and data experts.

gridview bombs on update - converting rowversion string to byte[]?

Hi. I have a gridview control on a web form (asp.net 2.0) that's bound to a
objectDataSource. The objectdatasource which is bound to a class I've
written in the DAL to read and update the database. The grid contains three
columns - an ID (GUID), a name (string) and a rowversion (timestamp), and
the data is passed to/from the page in an instance of a data entity object.
When I open the page the grid loads properly, but if I attempt to edit a
row, it bombs when I click on the UPDATE link with an error message of:
Cannot convert value of parameter 'rowversion' from 'System.String' to
'System.Byte[]' . The column rowversion is stored in the database as
timestamp, and in my business entity as a byte array. My guess is that when
it's passed into the gridview it's converted to a string, but when passing
it back to the DAL, the concersion from String to byte[] isn't working. The
bug is taking place after the rowupdating event, but before the update code
in the DAL gets called.

Any idea what''s going wrong?

Ben
Aug 15 '06 #1
5 5371
Hi Ben,

Can I ask why you map the timestamp field to a byte array rather than
DateTime? Based on my test, a byte array field will not show in the
GridView, how did you declare that? I'm curious to see your complete code
listing.

When you declare the ObjectDataSource in .aspx, you need to declare all the
parameters such as:

<UpdateParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="rowversion" Type="DateTime" />
</UpdateParameters>

When updating, ObjectDataSource will use this information to pass the
values to your business object's Update method.

I would recommend you use System.DateTime as the data type of the
rowversion.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 16 '06 #2
Hi Walter.

I've read in several places that the best way to store a timestamp column is
to use a byte[], although I'm a beginner in this, so I'm not sure if that's
true. However, storing it as DateTime doesn't work either:

DateTime rowversion;
//dr is a SqlDataReader
rowversion = dr.GetDateTime(dr.GetOrdinal("rowversion"));
//or
rowversion = dr.GetDateTime(dr.GetOrdinal("rowversion")).value;

both yield a System.InvalidCastException error

I created the ObjectDataSource visually. When I inspect the code on the page
I don't see anything about <UpdateParameters>. Here's the declaration:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetAllInstitutionList"
TypeName="DAL.DALInstitution"
DataObjectTypeName="DataEntities.InstitutionData"
DeleteMethod="DeleteInstitution"
UpdateMethod="UpdateInstitution"></asp:ObjectDataSource>

Here are the colum definitions on the page:
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="InstitutionId" HeaderText="InstitutionId"
SortExpression="InstitutionId" />
<asp:BoundField DataField="InstitutionName" HeaderText="InstitutionName"
SortExpression="InstitutionName" />
<asp:BoundField DataField="rowversion" HeaderText="rowversion"
SortExpression="rowversion" />
</Columns>
Ben

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:eU**************@TK2MSFTNGXA01.phx.gbl...
Hi Ben,

Can I ask why you map the timestamp field to a byte array rather than
DateTime? Based on my test, a byte array field will not show in the
GridView, how did you declare that? I'm curious to see your complete code
listing.

When you declare the ObjectDataSource in .aspx, you need to declare all
the
parameters such as:

<UpdateParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="rowversion" Type="DateTime" />
</UpdateParameters>

When updating, ObjectDataSource will use this information to pass the
values to your business object's Update method.

I would recommend you use System.DateTime as the data type of the
rowversion.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Aug 16 '06 #3
Hi Ben,

If you are using SQL Server timestamp field, don't include the field in
your DataSet. A timestamp field contains a unique value, generated by SQL
Server, which is updated whenever that record is updated.

And you are right, in .NET, reading timestamp field needs byte[].

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 17 '06 #4
I figured out how to make this work. Instead of storing the rowversion
column in the gridview, I add the column to the gridviews DataKeyNames
property.

Ben

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:Wc**************@TK2MSFTNGXA01.phx.gbl...
Hi Ben,

If you are using SQL Server timestamp field, don't include the field in
your DataSet. A timestamp field contains a unique value, generated by SQL
Server, which is updated whenever that record is updated.

And you are right, in .NET, reading timestamp field needs byte[].

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Aug 17 '06 #5
Hi Ben,

Glad to hear that you've solved the problem. By putting the rowversion
field in the DataKeyNames collection, it will also be passed to the methods
of ObjectDataSource.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 18 '06 #6

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

Similar topics

0
by: Douglas Osborne | last post by:
I am trying to pull the rowversion down from SQL and place it into my form as a hidden string variable. Then on postback I need to convert the string back to the byte array and see if it is the...
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: Bari Allen | last post by:
I'm trying to test for concurrency, using a SQL Stored Procedure on a RowVersion (timestamp) Field. The vb code I'm using is as follows Dim cmd As New SqlCommand("ConcurrencyCheck", cn) Dim...
0
by: Aws | last post by:
My crazy GridView !! I am using Visual Studio 2005, I have a problem with my GridView. I have one access .mdb table and when I update a record on the table EVERYTHING is perfect. I made a Web...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
7
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work...
4
by: tim.cavins | last post by:
I have a GridView populated by an ObjectDataSource. I am having issues passing the parameters to the objectdatasource. I have verified that the method is being called but none of the parameters...
2
by: rgparkins | last post by:
So, I've bitten the bullet and am converting some of my asp.net 1.1 sites to asp.net 2.0, now after many issues I have come to a stop with the objectdatasource and gridviews and maybe someone can...
1
by: janetb | last post by:
I have a gridview with an update capabilities - a textbox column (roomName), a dropdownlist(orgID), a dropdownlist(roomTypeID),a checkbox column (dialOut), a checkbox column (dialIn). When I try to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.