Programlama ve Elektronik

Programlama ve Elektronik (http://www.proelo.com/)
-   Örnek Kodlar (http://www.proelo.com/ornek-kodlar-87/)
-   -   C# Programlama Dilinde Kayıt Ekleme (http://www.proelo.com/ornek-kodlar-87/c-programlama-dilinde-kayit-ekleme-704/)

McDroPp 17. May 2008 03:39 AM

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ı");

}
}
}


Bütün Zaman Ayarları WEZ +3.5 olarak düzenlenmiştir. şu Anki Saat: 10:40 AM .