Tekil Mesaj gösterimi
Alt 17. May 2008, 03:39 AM   #1 (permalink)
McDroPp
Amatör
 
McDroPp - ait Kullanıcı Resmi (Avatar)
 
Üyelik tarihi: Mar 2008
Nerden: C# SQl Server 2008 İnformation Technology's Server Secretary And Aspx To lınk Tecnolojıes,Mybb
Mesajlar: 51
Standart C# Programlama Dilinde Kayıt Ekleme

C# Programlama Dilinde Kayıt Ekleme
--------------------------------------------------------------------------------
Veritabanına kayıt ekleme ile ilgili güzel bir örnek program.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication1
{
public partial class Form1 : Form
{SqlConnection conn;
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender EventArgs e)
{
conn = new SqlConnection();
conn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\ticaret.md f;Integrated Security=True;Connect Timeout=30;User Instance=True";
conn.Open();

kayitsayisi();

}
public void kayitsayisi()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT Count(*) FROM musteriler";
label6.Text = "Kayıt Sayısı:" + cmd.ExecuteScalar().ToString();
}

private void button1_Click(object sender EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = @"
INSERT INTO musteriler
(must_admust_kontakmust_sehirmust_ulke)
VALUES
(@ad@kontak@sehir@ulke)
";
cmd.Parameters.AddWithValue("@ad"textBox1.Text);
cmd.Parameters.AddWithValue("@kontak"textBox2.Tex t);
cmd.Parameters.AddWithValue("@sehir"textBox3.Text );
cmd.Parameters.AddWithValue("@ulke"textBox4.Text) ;
//çalıştır
cmd.ExecuteNonQuery();
kayitsayisi();
MessageBox.Show("Kayıt Başarıyla Tamamlandı");

}
}
}
__________________
بِسْــــــــــــــــــــــمِ اﷲِارَّحْمَنِ ارَّحِيم

-------------------------------------------------

Bu Soysuzlar Bu Vatansızlar Sarsada Yurdumu Ben Yaratan'dan Alırım Asil Kanı ve Gücü.
-------------------------------------------------
McDroPp isimli Üye şimdilik offline konumundadır   Alıntı ile Cevapla