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; using System.Data.Sql; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { SqlConnection baglanti = new SqlConnection("Data Source =DESKTOP-V2PKTHL;InitiaL Catalog=databasename;Integrated Security=True"); SqlCommand komut = new SqlCommand("insert into Persons(ogr_adi,ogr_soyadi,ogr_sinif,dersler)values(@adi,@soyadi,@sinif,@ders)",baglanti); baglanti.Open(); komut.Parameters.AddWithValue("@adi", textBox1.Text); komut.Parameters.AddWithValue("@soyadi", textBox2.Text); komut.Parameters.AddWithValue("@sinif", textBox3.Text); komut.Parameters.AddWithValue("@ders", textBox4.Text); int donen = komut.ExecuteNonQuery(); if (donen == 0) { MessageBox.Show("Hata"); } else if (donen == 1) { MessageBox.Show("Başarılı"); } baglanti.Close(); } private void label1_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { SqlConnection baglanti = new SqlConnection("Data Source =DESKTOP-V2PKTHL;InitiaL Catalog=databasename;Integrated Security=True"); DataTable tablo = new DataTable("Persons"); SqlDataAdapter adtr = new SqlDataAdapter("Select * from Persons",baglanti); baglanti.Open(); tablo.Clear(); adtr.Fill(tablo); dataGridView1.DataSource = tablo; baglanti.Close(); } } }