473,554 Members | 2,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
objectDataSourc e. The objectdatasourc e 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 5384
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 ObjectDataSourc e in .aspx, you need to declare all the
parameters such as:

<UpdateParamete rs>
<asp:Paramete r Name="id" Type="Int32" />
<asp:Paramete r Name="name" Type="String" />
<asp:Paramete r Name="rowversio n" Type="DateTime" />
</UpdateParameter s>

When updating, ObjectDataSourc e 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")).v alue;

both yield a System.InvalidC astException error

I created the ObjectDataSourc e visually. When I inspect the code on the page
I don't see anything about <UpdateParamete rs>. Here's the declaration:
<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
SelectMethod="G etAllInstitutio nList"
TypeName="DAL.D ALInstitution"
DataObjectTypeN ame="DataEntiti es.InstitutionD ata"
DeleteMethod="D eleteInstitutio n"
UpdateMethod="U pdateInstitutio n"></asp:ObjectDataS ource>

Here are the colum definitions on the page:
<Columns>
<asp:CommandFie ld ShowEditButton= "True" />
<asp:BoundFie ld DataField="Inst itutionId" HeaderText="Ins titutionId"
SortExpression= "Institutio nId" />
<asp:BoundFie ld DataField="Inst itutionName" HeaderText="Ins titutionName"
SortExpression= "InstitutionNam e" />
<asp:BoundFie ld DataField="rowv ersion" HeaderText="row version"
SortExpression= "rowversion " />
</Columns>
Ben

"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:eU******** ******@TK2MSFTN GXA01.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 ObjectDataSourc e in .aspx, you need to declare all
the
parameters such as:

<UpdateParamete rs>
<asp:Paramete r Name="id" Type="Int32" />
<asp:Paramete r Name="name" Type="String" />
<asp:Paramete r Name="rowversio n" Type="DateTime" />
</UpdateParameter s>

When updating, ObjectDataSourc e 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.comwr ote in message
news:Wc******** ******@TK2MSFTN GXA01.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 ObjectDataSourc e.

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
1501
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 same as the current row version. Any code for accomplishing this? Or is there a better way. Should I convert the byte array to a big int, then write...
8
5021
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 select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for...
5
2707
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 intID as integer = MyDataset.Tables("MyTable").Rows(0).Item("ID") cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add("@ReturnValue",...
0
2278
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 Setup Project and installed My Web Application on my Localhost and it works perfectly. When I install My Web Application on our “Production...
4
7222
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 - "Modified" of type DateTime - is hidden since it should not be edited by a user. The system handles the update for this column. So, I have hidden...
7
17309
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 either! Does anyone know how can I make this work? Thanks in advance!
4
6043
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 are being populated. Integers are being passed as 0 and strings are empty regardless of what I changed them to in Edit mode on the GridView. My...
2
3236
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 help! I have update, add adapter calls on the objectdatasource working well, however I have an issue with the delete call. In ASP.NET 2.0 I see...
1
3785
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 add another checkbox column, the sql database isn't updated properly with a 0/1 or false/true but with null. I've tried everything I can think of. Can...
0
8042
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7889
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6145
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5155
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2020
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1134
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
841
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.