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 difference between // comments, /* */ comments and /// comments?

495


What is anonymous methods in c#?

552


How many types of methods are there in c#?

520


List out the differences between array and arraylist in c#?

521


What is static noise?

503






How many constructors can a class have in c#?

477


What is platform independence"?

537


Is and as in c#?

507


What is firstordefault c#?

536


What is anonymous types in c#?

498


What is difference between class and abstract class in c#?

459


How to rotate an Image in C#?

578


Can we have multiple threads in one app domain?

517


What is difference between array and arraylist c#?

455


Is c# a backend language?

565