Vous êtes sur la page 1sur 3

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.

Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsFormsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { //ilk olarak bi baglant ayoruz SqlConnection baglanti =new SqlConnection(); baglanti.ConnectionString = "server=lab4-hoca;user=sa;pwd=a;database=Northwind;"; //connection string ile hangi bilgisayarn hangi data baseine hangi kullanc ad we ifryle baglanlacagn belirler sqlConn.Open();//baglant kurulur SqlCommand sqCom = new SqlCommand(); sqCom.Connection = sqlConn; sqCom.CommandText = "select * from products"; sqCom.CommandType = CommandType.Text; sqCom.ExecuteScalar(); DataTable dtProd = new DataTable(); SqlDataAdapter sqDa = new SqlDataAdapter(); sqDa.SelectCommand = sqCom;

//data adapter e bu komutun selectmi updatemi insertmi deletemi oldugunu belirlemeliyim sqDa.Fill(dtProd);// data table doldurur dataGridView1.DataSource = dtProd;// gridde gostermeyi saglar } private void button2_Click(object sender, EventArgs e) { SqlConnection sqlConn = new SqlConnection(); sqlConn.ConnectionString = "server=lab4-hoca;user=sa;pwd=a;database=Northwind;"; //connection string ile hangi bilgisayarn hangi data baseine hangi kullanc ad we ifryle baglanlacagn belirler sqlConn.Open();//baglant kurulur SqlCommand sqCom = new SqlCommand(); sqCom.Connection = sqlConn; sqCom.CommandText = "insert into Products (ProductName,UnitPrice) values ('" + textBox1.Text + "'," + numericUpDown1.Value.ToString() + ")"; ; sqCom.CommandType = CommandType.Text; sqCom.ExecuteNonQuery(); button1_Click(sender, e); } private void textBox1_TextChanged(object sender, EventArgs e) { } private void numericUpDown1_ValueChanged(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { //ilk olarak bi baglant ayoruz SqlConnection sqlConn = new SqlConnection(); sqlConn.ConnectionString = "server=lab4-hoca;user=sa;pwd=a;database=Northwind;"; //connection string ile hangi bilgisayarn hangi data baseine hangi kullanc ad we ifryle baglanlacagn belirler sqlConn.Open();//baglant kurulur SqlCommand sqCom = new SqlCommand(); sqCom.Connection = sqlConn; sqCom.CommandText = "select * from products"; sqCom.CommandType = CommandType.Text; sqCom.ExecuteScalar();

DataTable dtProd = new DataTable(); SqlDataAdapter sqDa = new SqlDataAdapter(); sqDa.SelectCommand = sqCom; //data adapter e bu komutun selectmi updatemi insertmi deletemi oldugunu belirlemeliyim sqDa.Fill(dtProd);// data table doldurur dataGridView1.DataSource = dtProd;// gridde gostermeyi saglar

SqlConnection baglanti =new SqlConnection(); baglanti.ConnectionString="Data Source=ARELIK\\SQLEXPRESS;Initial Catalog=okul;Integrated Security=True"; baglanti.Open(); SqlCommand sorgu = new SqlCommand(); sorgu.Connection = baglanti; sorgu.CommandText="insert into ogrenci (Numara,Ad,Soyad,Bkod) values('" + tbNumara.Text + "','" + tbAd.Text + "','" + tbSoyad.Text + "','" + tbBkod.Text + "')"; sorgu.CommandType = CommandType.Text; sorgu.ExecuteNonQuery(); bKaydet_Click(sender, e);

Vous aimerez peut-être aussi