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
What is the purpose of constructor in c#?
How do generics work in c#?
What are most desktop applications written in?
What is a clr host?
What is default boolean value in c#?
Are there constructors in c sharp?
What is the difference between “constant” and “readonly” variables in c#?
What is the implicit name and type of the parameter that gets passed into the class set method?
Name which controls do not have events?
How a two-dimensional array declared in C#?
Can abstract class be sealed in c#?
What is difference between singleordefault and firstordefault?
What is Implementation inheritance
Explain About multi level and multiple inheritance how to achieve in .net
Is string immutable in c#?