Ana içeriğe atla

Microsoft.Data.SqlClient Örnek VeriTabanı


using System;

using System.Data;

using Microsoft.Data.SqlClient;//Install-Package Microsoft.Data.SqlClient

using System.Windows.Forms;


namespace Sql_Try

{

    public partial class Form1 : Form

    {

        SqlConnection sqlVT = new SqlConnection(@"Data Source=DESKTOP-0B1GIRL;Initial Catalog=My_Form;Integrated Security=True;Encrypt=True;Trust Server Certificate=True");


        public Form1()

        {

            InitializeComponent();

        }


        private void button2_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            string Name = textBox_isim.Text;

            string Password = textBox_password.Text;

            try

            {

                if (sqlVT.State == ConnectionState.Closed)

                {

                    sqlVT.Open();

                }


                string parametre = "SELECT * FROM my_table WHERE name = @name AND password = @password";


                SqlCommand sqlCmd = new SqlCommand(parametre, sqlVT);

                sqlCmd.Parameters.AddWithValue("@name", textBox_isim.Text);

                sqlCmd.Parameters.AddWithValue("@password", textBox_password.Text);


                SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);

                DataTable dataTable = new DataTable();


                sda.Fill(dataTable);


                if (dataTable.Rows.Count > 0)

                {

                    HomePage homePage = new HomePage();

                    homePage.Show();

                    this.Hide();

                }

                else

                {

                    MessageBox.Show("Hata Bilgileri Kontrol ediniz!!");

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show("Hataaa ???", ex.Message);

            }

            finally

            {

                sqlVT.Close();

            }            

        }

    }

}

Yorumlar

Bu blogdaki popüler yayınlar

C# Delete

//using System.Data.SqlClient; //Yeni Güncelleme geldi //Araçlar>NuGet Paket Yöneticisi>Paket yöneticisi Konsole //Install-Package Microsoft.Data.SqlClient //Kodu Yapıştırdık //using System.Data.SqlClient;  Microsoft.Data.SqlClient şeklinde değiştir ve Sorun Çözüldü //Problem SqlConnection bağlantısının altı ve üzeri çizili idi yeni version 9 geldiği için yukarıdaki değişiklikler yapıldı using Microsoft.Data.SqlClient; namespace Update {     public partial class Form1 : Form     {         SqlConnection sqlBaglanti = new SqlConnection(@"Data Source=DESKTOP-0B1GIRL\SQLEXPRESS;Initial Catalog=TestVT;Integrated Security=True;TrustServerCertificate=True");         public Form1()         {             InitializeComponent();         }         //Güncelleme İşlemi         private void button1_Click(object sender, Even...

C# Forms ve ADO.NET ile SQL Server 2022'de SQLConnection bağlantısı ile INSERT İşlemi

// SQL bağlantı yolu için sistem paketinin yüklenmesi using System; using System.Data.SqlClient; using System.Windows.Forms; namespace VeriTabanıTestProjesi {     public partial class Form1 : Form     {         // SQL bağlantı nesnesinin tanımlanması         SqlConnection sqlBaglanti = new SqlConnection(@"Data Source=DESKTOP-0B1GIRL\SQLEXPRESS;Initial Catalog=TestVT;Integrated Security=True");         public Form1()         {             InitializeComponent();         }         private void button1_Click(object sender, EventArgs e)         {             // Veri Tabanında oluşabilecek hataların yakalanması             try             {                 // SQL bağlantısının a...