Click here to Skip to main content
16,018,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have one table called "Operator"and I want to retrieve a single column called "OperatorCode" and store it into a View state and later I want to retrieve single single values from View State What should i do..Please suggest

What I have tried:

ViewState["OprCode"] = Convert.ToString(dsbindoperator.Tables[0].Rows[0]["Opr_Code"]);

DataSet ds=(DataSet)ViewState["OprCode"];

But This is giving me error
Posted
Updated 3-Oct-16 3:08am

1 solution

ViewState["OprCode"] is a string that contains the value of Opr_Code, however you are trying to retrieve it as a DataSet

C#
string code = (string)ViewState["OprCode"];



or

C#
string code = ViewState["OprCode"] as string;
 
Share this answer
 
Comments
Member 12749751 3-Oct-16 9:29am    
Actually I have to retrieve single column for all the rows and I want to store all the values inside a view state and after wards one by one i have to fetch the values from view state
F-ES Sitecore 3-Oct-16 9:38am    
You'll need to use something that can be persisted in the ViewState like an array of strings (string[]). Build a string array of all the values by looping through the dataset a row at a time, and store that array in the ViewState.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900