Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. private void button3_Click(object sender, EventArgs e)
  2. {
  3. //OleDbCommand cmd = new OleDbCommand();
  4. System.Data.OleDb.OleDbDataAdapter da;
  5. //OleDbCommand cmd = con.CreateCommand();
  6. //OleDbCommand oleDbCmd = new OleDbCommand();
  7. oleDbCmd.Connection = con;
  8. con.Open();
  9. string sql = "SELECT * From Student2 where Enroll = '" + textBox1.Text + "'";
  10. da = new System.Data.OleDb.OleDbDataAdapter(sql, con);
  11.  
  12. OleDbDataReader myReader = oleDbCmd.ExecuteReader();
  13. OleDbDataReader myReader;
  14. myReader = oleDbCmd.ExecuteReader();
  15. int count = 0;
  16.  
  17. while (myReader.Read())
  18. {
  19. count = count + 1;
  20. }
  21. if (count == 1)
  22. {
  23.  
  24. DataTable t = new DataTable();
  25. da.Fill(t);
  26. dataGridView1.DataSource = t;
  27. }
  28. //}
  29. else
  30. {
  31. MessageBox.Show("Given ID Does not Exist!");
  32. }
  33.  
  34.  
  35. con.Close();
  36.  
  37. }
  38.  
  39. private void button3_Click(object sender, EventArgs e)
  40. {
  41. OleDbConnection con = new OleDbConnection("Your connection string");
  42. OleDbCommand cmd = new OleDbCommand(con);
  43. OleDbDataAdapter da;
  44. con.Open();
  45. string sql = "SELECT * From Student2 where Enroll = '" + textBox1.Text + "'";
  46. cmd.CommandText = sql;
  47. da = new OleDbDataAdapter(cmd);
  48.  
  49. DataTable t = new DataTable();
  50. da.Fill(t);
  51. if (t.Rows.COunt > 0)
  52. {
  53. dataGridView1.DataSource = t;
  54. }
  55. else
  56. {
  57. MessageBox.Show("Given ID Does not Exist!");
  58. }
  59. da.Dispose();
  60. cmd.Dispose();
  61. con.Close();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement