public partial class Guncelle : Form
{
public Guncelle()
{
InitializeComponent();
}
static string conString = "Server=Kutlay-;Database=MusteriTakip;Uid=sa;Password=kutlay;";
SqlConnection baglanti = new SqlConnection(conString);
private void btnAra_Click(object sender, EventArgs e)
{
baglanti.Open();
string kayit = "SELECT * from musteriler where musterino=@musterino";
//musterino parametresine bağlı olarak müşteri bilgilerini çeken sql kodu
SqlCommand komut = new SqlCommand(kayit, baglanti);
komut.Parameters.AddWithValue("@musterino", txtMusterino.Text);
//musterino parametremize textbox'dan girilen değeri aktarıyoruz.
SqlDataAdapter da = new SqlDataAdapter(komut);
SqlDataReader dr = komut.ExecuteReader();
if (dr.Read()) //Sadece tek bir kayıt döndürüleceği için while kullanmadım.
{
lblMusterino.Text = dr["musterino"].ToString();
txtTc.Text = dr["tcno"].ToString();
txtIsim.Text = dr["isim"].ToString();
txtSoyisim.Text = dr["soyisim"].ToString();
txtTelefon.Text = dr["telefon"].ToString();
txtAdres.Text = dr["adres"].ToString();
//Datareader ile okunan verileri form kontrollerine aktardık.
}
else
MessageBox.Show("Müşteri Bulunamadı.");
baglanti.Close();
}
}
}
baglanti.Open();
string kayit = "update musteriler set tcno=@tcno,isim=@isim,soyisim=@soyisim,telefon=@telefon,adres=@adres where musterino=@musterino";
// müşteriler tablomuzun ilgili alanlarını değiştirecek olan güncelleme sorgusu.
SqlCommand komut = new SqlCommand(kayit, baglanti);
//Sorgumuzu ve baglantimizi parametre olarak alan bir SqlCommand nesnesi oluşturuyoruz.
komut.Parameters.AddWithValue("@tcno", txtTc.Text);
komut.Parameters.AddWithValue("@isim", txtIsim.Text);
komut.Parameters.AddWithValue("@soyisim", txtSoyisim.Text);
komut.Parameters.AddWithValue("@telefon", txtTelefon.Text);
komut.Parameters.AddWithValue("@adres", txtAdres.Text);
komut.Parameters.AddWithValue("@musterino", lblMusterino.Text);
//Parametrelerimize Form üzerinde ki kontrollerden girilen verileri aktarıyoruz.
komut.ExecuteNonQuery();
//Veritabanında değişiklik yapacak komut işlemi bu satırda gerçekleşiyor.
baglanti.Close();
MessageBox.Show("Müşteri Bilgileri Güncellendi.");
cmd = new SqlCommand();
con.Open();
cmd.Connection = con;
cmd.CommandText = "insert into ogrenci(ogrenci_no,ogrenci_ad,ogrenci_soyad,ogrenci_sehir) values (" + textBox1.Text + ",'" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
cmd.ExecuteNonQuery(); //www.ahmetcansever.com
con.Close();
griddoldur();
string[] sayi = new string[5000];
string asd;
private void button1_Click(object sender, EventArgs e)
{
string Metin = txtveriler.Text;
char[] ayrac = { '\n' };
string[] kelimeler = Metin.Split(ayrac);
// for (int i = 0; i < 10; i++)
//{
int i = 0;
asd = kelimeler[i].ToString();
i++;
label1.Text += asd + "\n";
//}
// foreach (string okunan in kelimeler)
//sayi[i] = okunan.ToString();
// label1.Text += sayi[i].ToString();
}
}
}
http://ykara.blogcu.com/c-string-split-metodu-kullanarak-metni-kelimelere-bolmek/1650403
http://www.ahmetcansever.com/programlama/c-sql-server-veritabani-baglantisi-select-insert-update-delete/