I just updated the StudentID and StudentName into the database.
I use these following codes to see value in the textbox but when i want to select the row it should be ID row not StudentID.
I mean i want to see value with StudentID, not ID row.
I don’t want to use the ID row to see the StudentName.
I want to see StudentName when i enter StudentID.
sql = new SqlConnection(@"Data Source=PC-PC\PC;Initial Catalog=Test;Integrated Security=True");
adapter = new SqlDataAdapter("select * from Entry",sql);
dt = new DataTable();
adapter.Fill(dt);
textBox1.Text = dt.Rows[3]["StudentName"].ToString();
If studentID is primary key of table, then use:
Otherwise use
dt.Selectmethod.Btw mixing data access code with UI code is not very good idea
UPDATE: also you can use LINQ
UPDATE: If you are entering student id and want to get student name, then you can just retrieve student name from database, passing parameter to sql command:
Consider also returning only first entry (if StudentID is not PK) and verifying for DbNull.
UPDATE: If you need to retrieve several attributes of student, then I’d created class Student:
And filled its properties from data reader:
Then when you enter student id in text box, retrieve student from database and show its properties in controls: