C# da SQL Lite ile login işlemi

Bu yazıyı bir youtuber arkadaşımız için derliyorum. c# ile SQL Lite kullanarak login işlemi. Gerekli SQL Lite dll dosyası ekten indirilebilir.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SQLite; namespace Shop { public partial class Form1 : Form { public Form1() { InitializeComponent(); } SQLiteConnection baglanti = new SQLiteConnection("Data Source=Data/CRM.s3db");//Oluşturulan DB adını yazın SQLiteCommand cmd = new SQLiteCommand();//SQL komutunu olusturduk. Her zaman yeniden oluşturmamak için SQLiteDataReader dr = null;//Baş bir data reader oluşturduk. Okunan verileri kullanmak için private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { try { cmd = new SQLiteCommand(@"select kullaniciAdi, sifre from kullanici where kullaniciAdi = '" + textBox1.Text + "' and sifre = '" + textBox2.Text + "'", baglanti); //Sorgumuz ve yukarıda oluşturduğumuz baglantı cumlesi dr = cmd.ExecuteReader();// data readeri sql komutumuzdan gelen verilerle doldurduk if (dr.Read())//eğer datareader okunursa bunları yapıcak { /*buraya kullanıcı adı şifre doğru okunursa yapılacak işleri yazın // // */ } else//Eğer kullanıcı adı şifre hatalıysa { MessageBox.Show("Hatalı kullanıcı adı ya da şifre.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dr.Close();//bağlatı ve datareaderı kapatmamız gerekli burada onları kapatıyoruz. baglanti.Close(); } } catch (Exception ex)//Daha detaylı bir hata mesajı için bu kodları uygulayın { dr.Close();//hata oluşursa diye bağlatı ve datareaderı kapatmamız gerekli burada kapatıyoruz. baglanti.Close(); MessageBox.Show(this, string.Format("{0}\r\n\r\nHata Türü: {1}", ex.Message, ex.GetType().ToString()), "Hatası oluştu"); } } } } |
1 |
1 |
C# da SQL Lite ile login işlemi Konusuna 1 Yorum Yapıldı
Çok işime yaradı. günlerdir arıyordum.