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 func c#?

764


Assembly Code. in Rejester AL. How do Contast Replece( or Change): Bit D3 With Bit D4 and Bit D2 With Bit D5 and Bit D1 With Bit D6 and Bit D0 With Bit D7 I am Not Know Very Well Write English.

1657


What is the difference between properties and indexer in c#?

610


Define delegation in .net?

664


Explain what are the steps for creating clr trigger?

647


What is dynamic object in c#?

690


What is type safe code?

659


What is a static class in c#?

692


I need code to connect ohter systems in the LAN and i want to display my website image over there and i want explain as a admin through phone. So i need code to access other system using C-Sharp. Any one please help me.Please give me the code. Advace thanks.

1669


What is the difference between serialization and deserialization in c#?

643


How do you create dlls in .NET

779


What is indexer c#?

643


What is the advantage of generics in c#?

681


Why are strings immutable c#?

639


What is eager and lazy loading in c#?

642