Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.OleDb;
- namespace carti
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- OleDbConnection conn;
- private void Form1_Shown(object sender, EventArgs e)
- {
- string cs = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DB1.accdb;Persist Security Info=True";
- conn = new OleDbConnection(cs);
- try
- {
- conn.Open();
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- // creez o comanda select pe conexiunea conn
- OleDbCommand c = new OleDbCommand("SELECT * FROM carti", conn);
- OleDbDataAdapter da = new OleDbDataAdapter(c);
- // creez tabel de date
- DataTable t = new DataTable();
- // pun datele din adaptor in tabel
- da.Fill(t);
- // pun din tabel in datagrid view
- dataGridView1.DataSource = t;
- }
- private void button2_Click(object sender, EventArgs e)
- {
- // citesc datele din textbox
- string titlu = textBox1.Text;
- string autor = textBox2.Text;
- // creez o comanda insert into
- string q = "INSERT * INTO carti(Titlu, Autor)";
- q = q + "VALUES ('" + titlu + "', '" + autor + "')";
- OleDbCommand c = new OleDbCommand(q, conn);
- MessageBox.Show(q);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement