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

difference between keyword internal and protected?

5 Answers   HCL,


Explain the difference between directcast and ctype.

0 Answers  


What is the meaning of 0 in c#?

0 Answers  


How do you implement multiple inheritance in .NET?

10 Answers   Microsoft,


What are the different types of literals in c#?

0 Answers  






what is object-oriented programming (oop) language?

0 Answers  


What is windows forms in c#?

0 Answers  


Explain the importance and use of each, version, culture and publickeytoken for an assembly.

0 Answers  


What is a method signature?

0 Answers  


What is the difference between firstordefault and first?

0 Answers  


If I return out of a try/finally in c#, does the code in the finally-clause run?

0 Answers  


How do I do implement a trace and assert?

0 Answers  


Categories