DataRow problem

C

cmrchs

Hi,

how do I 'save' a DataRow-object in ViewState or Session-object ?

Trying :
Session["Row"] = myDataSet.Tables[0].Rows[0];

results in an error :

The type 'System.Data.DataRow' must be marked as
Serializable or have a TypeConverter other than
ReferenceConverter to be put in viewstate

Who can help ?

Thnx

Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
W

William Ryan eMVP

Hi Chris:

I'm not sure what your problem is but this code works fine:
Dim dt As New DataTable

Dim dc As New DataColumn("Test", System.Type.GetType("System.String"))

dt.Columns.Add(dc)

Dim dro As DataRow = dt.NewRow

dro(0) = "Hello"

dt.Rows.Add(dro)

Session("MyVar") = dt.Rows(0)

Dim s As String = CType(Session("MyVar"), DataRow)(0).ToString

I did the same thing in C# without a problem too:
DataTable dt = new DataTable();

DataColumn dc = new DataColumn("Test",
System.Type.GetType("System.String"));

dt.Columns.Add(dc);

DataRow dro = dt.NewRow();

dro[0] = "Hello";

dt.Rows.Add(dro);

Session["Test"] = dt.Rows[0];



So I suspect the problem is elsewhere.



HTH,



Bill



www.devbuzz.com

www.knowdotnet.com




Chris C said:
Hi,

how do I 'save' a DataRow-object in ViewState or Session-object ?

Trying :
Session["Row"] = myDataSet.Tables[0].Rows[0];

results in an error :

The type 'System.Data.DataRow' must be marked as
Serializable or have a TypeConverter other than
ReferenceConverter to be put in viewstate

Who can help ?

Thnx

Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 
M

Miha Markic [MVP C#]

Hi Chris,

I think that session requires serializable classes and DataRow isn't.
Try putting whole Tables[0] into the session variable instead of just row.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Chris C said:
Hi,

how do I 'save' a DataRow-object in ViewState or Session-object ?

Trying :
Session["Row"] = myDataSet.Tables[0].Rows[0];

results in an error :

The type 'System.Data.DataRow' must be marked as
Serializable or have a TypeConverter other than
ReferenceConverter to be put in viewstate

Who can help ?

Thnx

Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 

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

using Session-object ?? 1
DataRow in ViewState 2
grid scroll 2
Databinder.eval Formatting 1
sorting DataGrid 1
Distinct Values from a Datatable 3
Intellisense 3
another obj ref error/ need help here 5

Top