Asp.NET - SqlConnection ile Veritabanına Veri Eklemek.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;

namespace veriekle
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        string resimdosyayolu;
        protected void Button1_Click(object sender, EventArgs e)
        {

            if (FileUpload1.HasFile)
            {
                FileUpload1.SaveAs(Server.MapPath("~/filmresim/" + FileUpload1.FileName));
                resimdosyayolu = Path.GetFileName(FileUpload1.FileName);
            }

            SqlConnection baglanti = new SqlConnection(@"Data source=lab2-PC_OGRETME\SQLEXPRESS;initial catalog=Film;integrated security=true;");
            baglanti.Open();
            SqlCommand sorgu = new SqlCommand("Insert Into Filmler(filmAdi,aciklama,cikisTarihi,filmAfis,kategoriId,yonetmen) values (@filmAdi,@aciklama,@cikisTarihi,@filmAfis,@kategoriId,@yonetmen)", baglanti);
            sorgu.Parameters.AddWithValue("@filmAdi", TextBox1.Text);
            sorgu.Parameters.AddWithValue("@aciklama", TextBox2.Text);
            sorgu.Parameters.AddWithValue("@cikisTarihi", DateTime.Parse(Calendar1.SelectedDate.ToString()));
            sorgu.Parameters.AddWithValue("@filmAfis", resimdosyayolu);
            sorgu.Parameters.AddWithValue("@kategoriId",int.Parse(TextBox3.Text));
            sorgu.Parameters.AddWithValue("@yonetmen", TextBox4.Text);
            sorgu.ExecuteNonQuery();
            baglanti.Close();
            Label1.Text = "Veriler Başarı ile Kaydedildi";

        }
    }
}

Yorumlar

Bu blogdaki popüler yayınlar

SQLite Değişken tipleri ve Komutları

Mobil Programlama - Not Hesaplama Uygulaması

Sistem Analizi ve Tasarımı Proje Sonu Bilgilendirme