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

Distinguish between a class and struct?

0 Answers  


What is the difference between an implicit conversion and an explicit conversion?

0 Answers  


What is disco?

0 Answers  


what is the diference between casting and converting?

2 Answers  


What is delay signing..??

1 Answers   HCL,






What is a pre-requisite for connection pooling?

1 Answers  


What is hashset c#?

0 Answers  


Is dictionary a collection?

0 Answers  


You are creating a custom usercontrol, some of the newly created properties are shown in the properties window. How you can hide a new property named theme from the properties window?

0 Answers  


Can int be null in c#?

0 Answers  


how can i get this 123456789 1234 6789 123 789 12 89 1 9

1 Answers   Excel,


Difference between value and reference type. What are value types and reference types?

0 Answers  


Categories