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

515


Explain dataadapter.update method in .net?

526


What is the purpose of a constructor in c#?

478


Explain about c# language.

607


How many aware interfaces are there?

494






When would you use generics in your code c#?

498


Difference between Value type & reference types ? and give the example in .Net?

529


What is the real use of interface in c#?

476


How many constructors can a class have c#?

482


What is the usage of OLE?

592


How do you use nullable?

512


Write down the c# syntax to catch an exception

533


In dynamic link library, which api is used for load library?

531


What is the implicit name of the parameter that gets passed into the set method/property of a class?

505


What is the difference between protected and internal in c#?

472