Form1.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace WindowsFormsApp1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. SqlConnection connection;
  16. SqlCommand command;
  17. SqlDataAdapter adapter;
  18. DataTable table;
  19. public Form1()
  20. {
  21. InitializeComponent();
  22. connection = new SqlConnection("Server=Class31000;Database=aero;Trusted_connection=true;");
  23. command = new SqlCommand();
  24. command.Connection = connection;
  25. command.CommandType = CommandType.Text;
  26. adapter = new SqlDataAdapter(command);
  27. table = new DataTable();
  28. }
  29. private void ShowTable(string text)
  30. {
  31. dataGridView1.Columns.Clear();
  32. dataGridView1.DataSource = null;
  33. command.CommandText = text;
  34. table.Clear();
  35. adapter.Fill(table);
  36. dataGridView1.DataSource = table;
  37. }
  38. private void Form1_Load(object sender, EventArgs e)
  39. {
  40. ShowTable("Select * From Users");
  41. }
  42. private void button1_Click(object sender, EventArgs e)
  43. {
  44. Form2 b = new Form2();
  45. b.Show();
  46. this.Hide();
  47. }
  48. }
  49. }