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

Answers were Sorted based on User's Feedback



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

Answer / karthikeyan

String connectionString = @"Data
Source=.\SQLExpress;Initial Catalog=Nwind;Integrated
Security=SSPI";
SqlConnection con = new SqlConnection(connectionString);
string conString = "Select * From Customers";
SqlDataAdapter dataAdpter = new SqlDataAdapter(conString,
con);
DataSet ds = new DataSet();
dataAdpter.Fill(ds);
ds.Tables[0].Columns[0].ReadOnly = true;
dataGridView1.DataSource = ds.Tables[0];

Is This Answer Correct ?    10 Yes 1 No

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

Answer / 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

More C Sharp Interview Questions

Why it's said that writing into .NET Application Configuration Files is a Bad Idea?

0 Answers   DELL,


Explain manifest & metadata in c#.

0 Answers  


What does the parameter Initial Catalog define inside Connection String?

5 Answers  


What is difference between out and ref in c#?

0 Answers  


What is token in c#?

0 Answers  






What is cookies in c# asp net?

0 Answers  


What is a resource? Provide an example from your recent project.

2 Answers   IBM, Logica CMG, Wipro,


What is the advantage of singleton class?

0 Answers  


What is an assembly loader?

0 Answers  


Explain the difference between a sub and a function in c#.

0 Answers  


What is the base class for array types?

0 Answers  


what is the use of master pages. how to use it

2 Answers  


Categories