//Bağlantı :
con = new SqlConnection(@"server = (localdb)\mssqllocaldb; initial catalog = sqlders; integrated security = true");
data = new SqlDataAdapter("SELECT * FROM [Table]", con); // con veriyi çekme
SqlConnection con;
SqlDataAdapter data;
SqlCommand komut;
//INSERT:
string sorgu = " INSERT INTO [Table](isim,soyad,tel,gtarih,çtarih) VALUES (@isim,@soyad,@tel,@gtarih,@çtarih)";
komut = new SqlCommand(sorgu, con);
con.Open();
komut.Parameters.AddWithValue("[USER=92828]@Isim[/USER]", isimtxt.Text);
komut.Parameters.AddWithValue("@soyad", soyadtxt.Text);
komut.Parameters.AddWithValue("[USER=326213]@tel[/USER]", teltxt.Text);
komut.Parameters.AddWithValue("@gtarih", gtrhtxt.Value);
komut.Parameters.AddWithValue("@çtarih", çtrhtxt.Value);
komut.ExecuteNonQuery();
con.Close();
MessageBox.Show("Kullanıcı Eklendi");
//Update:
string sorgu = "UPDATE [Table] SET isim=@isim,soyad=@soyad,tel=@tel,gtarih=@gtarih,çtarih=@çtarih WHERE Id=@Id"; // databasedeki isimiler
komut = new SqlCommand(sorgu, con);
komut.Parameters.AddWithValue("@Id", Convert.ToInt32(ıdtxt.Text));
komut.Parameters.AddWithValue("[USER=92828]@Isim[/USER]", isimtxt.Text);
komut.Parameters.AddWithValue("@soyad", soyadtxt.Text);
komut.Parameters.AddWithValue("[USER=326213]@tel[/USER]", teltxt.Text);
komut.Parameters.AddWithValue("@gtarih", gtrhtxt.Value);
komut.Parameters.AddWithValue("@çtarih", çtrhtxt.Value);
con.Open();
komut.ExecuteNonQuery();
con.Close();
MessageBox.Show("Kullanıcı Güncellendi");
//Delete:
string sorgu = " DELETE FROM [Table] Where Id = @Id";
komut = new SqlCommand(sorgu, con);
komut.Parameters.AddWithValue("@Id", Convert.ToInt32(ıdtxt.Text));
con.Open();
komut.ExecuteNonQuery();
con.Close();
// void kullanıcı();
MessageBox.Show("Kullanıcı Silindi");