C# Code for How to set readonly property to Id(database)
value?
Answers were Sorted based on User's Feedback
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 |
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 |
What is difference between sleep () and wait ()?
What is difference between asp net and c# net?
How do you generate documentation from the C# file commented properly with a command-line compiler?
What is concatenation and when should it be used?
What are the benefits of using the aggregate method in linq?
Give an example of a ctype.
What is a singleton unity?
What is difference between constants and readonly in c#?
How is lazy loading achieved?
What is the difference between CONST and READONLY?
What is the difference between string and stringbuilder in c#?
Is c# an open source?