Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ========================= Domain.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Kaseti
- {
- class Domain
- {
- string Title;
- public string Title1
- {
- get { return Title; }
- set { Title = value; }
- }
- string zanr;
- public string zanr1
- {
- get { return zanr; }
- set { zanr= value; }
- }
- string rezisior;
- public string rezisior1
- {
- get { return rezisior; }
- set { rezisior = value; }
- }
- }
- }
- ============================ Person.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Kaseti
- {
- class Person
- {
- public string Title1 { get; set; }
- public string zanr1 { get; set; }
- public string rezisior1 { get; set; }
- }
- }
- ==================================== Broker.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data.OleDb;
- using System.Data;
- using System.Windows.Forms;
- namespace Kaseti
- {
- class Broker
- {
- OleDbConnection connection;
- OleDbCommand command;
- private void ConnectTo()
- {
- connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\student\\Documents\\kaseti.accdb");
- command = connection.CreateCommand();
- }
- public Broker()
- {
- ConnectTo();
- }
- public void Insert(Person p)
- {
- try
- {
- command.CommandText = "INSERT INTO Kaseti( [Title], [zanr], [rezisior]) VALUES ("+ "'" + p.Title1 + "'" + "," + "'" + p.zanr1 + "'" + "," + "'" + p.rezisior1 + "'" + ")";
- command.CommandType = CommandType.Text;
- connection.Open();
- command.ExecuteNonQuery();
- }
- catch (Exception)
- {
- MessageBox.Show("Некоректни данни! Моля въведете отново!");
- }
- finally
- {
- if (connection != null)
- {
- connection.Close();
- }
- }
- }
- }
- }
- ============================= Form1.cs
- 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;
- namespace Kaseti
- {
- public partial class Form1 : Form
- {
- Broker b = new Broker();
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- label2.Text = "title";
- label3.Text = "zanr";
- label4.Text = "resisior";
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- Person p = new Person();
- p.Title1 = textBox2.Text;
- p.zanr1 = textBox3.Text;
- p.rezisior1 = textBox4.Text;
- b.Insert(p);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement