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.SqlClient;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void addbutton_Click(object sender, EventArgs e)
- {
- try
- {
- String Query = string.Format("INSERT INTO dbo.Kierunek (nazwa_kierunku,wydział_id) VALUES ('{0}','{1}')", nazwakierunkutxt.Text, wydzialidtxt.Text);
- SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
- builder.DataSource = "172.30.52.237,1500";
- builder.UserID = "sa";
- builder.Password = "Matis123";
- builder.InitialCatalog = "Uczelnia2";
- using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
- {
- SqlCommand Command = new SqlCommand(Query, connection);
- Command.Connection.Open();
- Command.ExecuteNonQuery();
- MessageBox.Show("Saved");
- connection.Close();
- }
- }
- catch (SqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void Delete_Click(object sender, EventArgs e)
- {
- try
- {
- String Query = string.Format("DELETE FROM dbo.Kierunek WHERE (id_kierunku='{0}')", id_kierunkutxt.Text);
- SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
- builder.DataSource = "172.30.52.237,1500";
- builder.UserID = "sa";
- builder.Password = "Matis123";
- builder.InitialCatalog = "Uczelnia2";
- using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
- {
- SqlCommand Command = new SqlCommand(Query, connection);
- Command.Connection.Open();
- Command.ExecuteNonQuery();
- MessageBox.Show("Deleted");
- connection.Close();
- }
- }
- catch (SqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void Select_Click(object sender, EventArgs e)
- {
- try
- {
- String Query = string.Format("SELECT nazwa_kierunku, wydział_id FROM dbo.Kierunek WHERE (id_kierunku='{0}')", id_kierunkutxt.Text);
- SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
- builder.DataSource = "172.30.52.237,1500";
- builder.UserID = "sa";
- builder.Password = "Matis123";
- builder.InitialCatalog = "Uczelnia2";
- using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
- {
- SqlCommand Command = new SqlCommand(Query, connection);
- Command.CommandType = CommandType.Text;
- Command.Connection.Open();
- SqlDataReader dr = Command.ExecuteReader();
- if (dr.Read())
- {
- //id_kierunkutxt.Text = dr[1].ToString();
- nazwakierunkutxt.Text = dr[0].ToString();
- wydzialidtxt.Text = dr[1].ToString();
- }
- dr.Close();
- }
- }
- catch (SqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void Update_Click(object sender, EventArgs e)
- {
- try
- {
- String Query = string.Format("UPDATE dbo.Kierunek SET nazwa_kierunku='{0}',wydział_id='{1}' WHERE id_kierunku='{2}'",nazwakierunkutxt.Text,wydzialidtxt.Text, id_kierunkutxt.Text);
- SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
- builder.DataSource = "172.30.52.237,1500";
- builder.UserID = "sa";
- builder.Password = "Matis123";
- builder.InitialCatalog = "Uczelnia2";
- using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
- {
- SqlCommand Command = new SqlCommand(Query, connection);
- Command.Connection.Open();
- Command.ExecuteNonQuery();
- MessageBox.Show("Updated");
- connection.Close();
- }
- }
- catch (SqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement