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.Data.Sql; using System.Data.SqlClient; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { SqlConnection baglanti = new SqlConnection("Data Source=DESKTOP-V2PKTHL;Initial Catalog=itudeneme;Integrated Security=True"); SqlCommand komut = new SqlCommand("insert into itudeneme1 (ogr_ad, ogr_soyad, 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("Kayıt Başarılı."); } baglanti.Close(); } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { SqlConnection baglanti = new SqlConnection("Data Source=DESKTOP-V2PKTHL;Initial Catalog=itudeneme;Integrated Security=True"); DataTable tablo = new DataTable("itudeneme1"); SqlDataAdapter aptr = new SqlDataAdapter("Select * from itudeneme1", baglanti); baglanti.Open(); tablo.Clear(); aptr.Fill(tablo); dataGridView1.DataSource = tablo; baglanti.Close() ; } private void Form1_Load(object sender, EventArgs e) { SqlConnection baglanti = new SqlConnection("Data Source=DESKTOP-V2PKTHL;Initial Catalog=itudeneme;Integrated Security=True"); DataTable tablo = new DataTable("itudeneme1"); SqlDataAdapter aptr = new SqlDataAdapter("Select * from itudeneme1", baglanti); baglanti.Open(); tablo.Clear(); aptr.Fill(tablo); dataGridView1.DataSource = tablo; baglanti.Close(); } } }