Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

C# Code for How to set readonly property to Id(database)
value?

Answer Posted / deepak ray

Just retrieve the id from database using reader or dataset
and store the id in a string.
and
set the string in a public readonly property like this.


string _UserId;
public string UserId
{ get { return _UserId; } }

SqlDataReader dr = null;
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
_UserId = dr["UserId"].ToString();
}
dr.Close();
dr.Dispose();

Is This Answer Correct ?    10 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of constructor in c#?

858


How do generics work in c#?

908


What are most desktop applications written in?

972


What is a clr host?

961


What is default boolean value in c#?

970


Are there constructors in c sharp?

965


What is the difference between “constant” and “readonly” variables in c#?

1011


What is the implicit name and type of the parameter that gets passed into the class set method?

877


Name which controls do not have events?

1050


How a two-dimensional array declared in C#?

967


Can abstract class be sealed in c#?

889


What is difference between singleordefault and firstordefault?

916


What is Implementation inheritance

972


Explain About multi level and multiple inheritance how to achieve in .net

1035


Is string immutable in c#?

1004