0% found this document useful (0 votes)
17 views

04/05/2011 SQL Connection Dersi: Using Using Using Using Using Using Using Using Using Namespace Public Partial Class

The document discusses connecting to a SQL database and querying user login information. It shows code for opening a SQL connection, executing queries to retrieve user names and passwords, and checking supplied login credentials against the database. The code also handles displaying login success or failure messages. The document suggests adding collation to queries to make username and password comparisons case sensitive.

Uploaded by

Necmi Yılmaz
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

04/05/2011 SQL Connection Dersi: Using Using Using Using Using Using Using Using Using Namespace Public Partial Class

The document discusses connecting to a SQL database and querying user login information. It shows code for opening a SQL connection, executing queries to retrieve user names and passwords, and checking supplied login credentials against the database. The code also handles displaying login success or failure messages. The document suggests adding collation to queries to make username and password comparisons case sensitive.

Uploaded by

Necmi Yılmaz
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

04/05/2011

SQL CONNECTION DERSİ

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection("data source=YAZILIM1\\yazilim1;
initial catalog=Baglanti; Integrated Security=true");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT KULLANICI FROM KullaniciGirisi",
con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{

MessageBox.Show("Kullanıcı Adı: "+dr[0].ToString()+" "+"Şifre: "+dr[1].ToString());

dr.Close();
con.Close();

}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection("data source=YAZILIM1; initial
catalog=Baglandı; Integrated Security=true");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT KULLANICI, SİFRE FROM
KullaniciGirisi", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
MessageBox.Show("Kullanıcı Adı: "+dr[0].ToString()+" "+"Şifre:
"+dr[1].ToString());

dr.Close();
con.Close();

private void button2_Click(object sender, EventArgs e)


{
KullaniciGirisi(textBox1.Text.ToString(), textBox2.Text.ToString());

public void KullaniciGirisi(string adi, string sifre)


{
SqlConnection con = new SqlConnection("data source=YAZILIM1; initial
catalog=Baglandı; Integrated Security=true");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT KULLANICI, SİFRE FROM
KullaniciGirisi WHERE KULLANICI=@adi and SİFRE=@sifre", con);
cmd.Parameters.AddWithValue("@adi", adi);
cmd.Parameters.AddWithValue("@sifre", sifre);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Form2 frm = new Form2();
frm.Show();
}
else
{
MessageBox.Show("Sifre veya gecersiz...!");
dr.Close();
con.Close();
}
}
}
}

SqlCommand cmd = new SqlCommand("SELECT KULLANICI, SİFRE FROM KullaniciGirisi WHERE


KULLANICI Collate SQL_Latin1_General_CP1254_CS_AS = @adi and SİFRE Collate
SQL_Latin1_General_CP1254_CS_AS =@sifre", con);

CASE SENSITIVE OZELLİĞİNİ

Collate SQL_Latin1_General_CP1254_CS_AS = @adi and SİFRE Collate


SQL_Latin1_General_CP1254_CS_AS =@sifre

You might also like