J Vs

J Vs

  • 1.6k
  • 52
  • 2.7k

How to display data from Access database? C#

Aug 5 2019 10:45 PM
  1. private void Bsearch_Click(object sender, EventArgs e)  
  2. {  
  3. try  
  4. {  
  5. connection.Open();  
  6. OleDbCommand command = new OleDbCommand();  
  7. command.Connection = connection;  
  8. string query = "select* from Students WHERE Firstname LIKE '" + tbsearchid.Text + "'";  
  9. command.CommandText = query;  
  10.   
  11. OleDbDataReader reader = command.ExecuteReader();  
  12. while (reader.Read())  
  13. {  
  14. tbFname.Text = reader["Firstname"].ToString();  
  15. tbLname.Text = reader["Lastname"].ToString();  
  16. /*this part*/ tbmulti.Text = reader[(Course1: + "Course1") (Course2 + "Course2")].ToString(); // my access db has 10 courses colums course1 -course10  
  17. /*this part*/ tbavg.Text = reader[ provide the avg of the courses]  
  18. /*this part*/ tbmax.Text = reader[provides the max of the courses]  
  19.   
  20. }  
  21.   
  22. connection.Close();  
  23.   
  24. }  
  25. catch (Exception ex)  
  26. {  
  27. MessageBox.Show("Error " + ex);  
  28. }  
 
 
 
 

Answers (3)