Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  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.OleDb;
  11.  
  12. namespace carti
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. OleDbConnection conn;
  22.  
  23. private void Form1_Shown(object sender, EventArgs e)
  24. {
  25. string cs = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DB1.accdb;Persist Security Info=True";
  26. conn = new OleDbConnection(cs);
  27.  
  28. try
  29. {
  30. conn.Open();
  31. }
  32. catch(Exception ex)
  33. {
  34. MessageBox.Show(ex.Message);
  35. }
  36. }
  37.  
  38. private void button1_Click(object sender, EventArgs e)
  39. {
  40. // creez o comanda select pe conexiunea conn
  41. OleDbCommand c = new OleDbCommand("SELECT * FROM carti", conn);
  42.  
  43. OleDbDataAdapter da = new OleDbDataAdapter(c);
  44. // creez tabel de date
  45. DataTable t = new DataTable();
  46. // pun datele din adaptor in tabel
  47. da.Fill(t);
  48. // pun din tabel in datagrid view
  49. dataGridView1.DataSource = t;
  50. }
  51.  
  52. private void button2_Click(object sender, EventArgs e)
  53. {
  54. // citesc datele din textbox
  55. string titlu = textBox1.Text;
  56. string autor = textBox2.Text;
  57. // creez o comanda insert into
  58. string q = "INSERT * INTO carti(Titlu, Autor)";
  59. q = q + "VALUES ('" + titlu + "', '" + autor + "')";
  60. OleDbCommand c = new OleDbCommand(q, conn);
  61. MessageBox.Show(q);
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement