Arkadaşlar bu yazıda veritabında kayıtlı olan bir veriyi yeni veriiler ile güncellemenin nasıl olacağını bir örnek olarak göstermeye çalışacağım.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class ayarlar : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection baglanti = new SqlConnection("Data Source=ekrem-pc\\SQL2008R2;
Initial Catalog=vt;User Id=admin;Password=1234");
baglanti.Open();
SqlCommand guncelle = new SqlCommand("update ayarlar set smtpSunucusu=
'"+TextBox1.Text+"' where id='1'", baglanti);
SqlCommand guncelle2 = new SqlCommand("update ayarlar set smtpKullaniciAdi=
'"+TextBox2.Text+"' where id='1'", baglanti);
SqlCommand guncelle3 = new SqlCommand("update ayarlar set smtpSifre=
'"+TextBox3.Text+"' where id=1", baglanti);
guncelle.Parameters.AddWithValue("@smtpSunucusu", TextBox1.Text);
guncelle2.Parameters.AddWithValue("@smtpKullaniciAdi", TextBox2.Text);
guncelle3.Parameters.AddWithValue("@smtpSifre", TextBox3.Text);
guncelle.ExecuteNonQuery();
guncelle2.ExecuteNonQuery();
guncelle3.ExecuteNonQuery();
baglanti.Close();
Response.Write("veri başarı ile güncellendi");
}
}
Bu kadar basit,yorum yazmayı unutmayınız:)
asp.net-c# veri tabanı güncelleme

0 yorum:
Yorum Gönder