Login Form

 

Merhaba arkadaşlar bu makalemizde Kullanıcı login formunu oluşturacağız.



 

 

 

 

 

 

 

 

Şekil 1



 

Sql Serverimiza bağlanıyoruz.

 


 

 

 

 

 

 

 

 

Şekil 2

 

Kullanıcı girişi yapacağımız tabloyu oluşturuyoruz

 


 

 

 

 

 

 

Şekil 3



 

TextBox ın Password kısmına * giriyoruz.

 


 

Şekil 4

 









Form1.cs

 

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.Threading.Tasks;

using System.Windows.Forms;

 

 

 

 

namespace login_form

{

    public partial class Form1 : Form

    {

        SqlConnection con = new SqlConnection("Data Source=SIRIUS\\SQLEXPRESS;Initial Catalog=login;User ID=sa;Password=2344;Integrated Security=True");

 

        public Form1()

        {

            InitializeComponent();

        }

 

        private void btnLogin_Click(object sender, EventArgs e)

        {

            if (textBox1.Text == "")

 

            {

 

                MessageBox.Show("Please enter username" + (char)13 + "Lutfen kullanici adi giriniz!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

 

                textBox1.Focus();

 

                return;

 

            }

 

            if (textBox2.Text == "")

 

            {

 

                MessageBox.Show("Please enter password" + (char)13 + "Lutfen sifre giriniz!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

 

                textBox2.Focus();

 

                return;

 

            }

 

            try

 

            {

 

                con.Open();

 

                SqlDataAdapter da = new SqlDataAdapter("Select * From dbo.users where username='" + textBox1.Text + "' and password='" + textBox2.Text + "'", con);

 

                //DataTable dt = new DataTable();

                DataSet ds = new DataSet();

                da.Fill(ds);

               

                for (int i = 0; i <= ds.Tables[0].Rows.Count + 1; i++)

                {

                    //if (dt.Rows[0][0].ToString() == i.ToString())

                    if (ds.Tables[0].Rows[0][0].ToString() == i.ToString())

                    {

 

                        Form form = new Form();

 

                        form.Show();

 

                        this.Hide();

 

                    }

                }

                //for (int i = 0; i <= 2; i++)

               // {

                 //   if (dt.Rows[0][0].ToString() != i.ToString())

                   // {                    

                   // else { MessageBox.Show("Please check user username and password!" + (char)13 + "Lutfen kullanici adini ve sifreyi kontrol ediniz!"); }

                        //MessageBox.Show("Please check user username and password!" + (char)13 + "Lutfen kullanici adini ve sifreyi kontrol ediniz!");

                        con.Close();

                   // }

                       

                   // }

            }

           

 

            catch (Exception ex)

 

            {

 

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

 

            }

        }

 

        private void btnReset_Click(object sender, EventArgs e)

        {

          

            textBox1.Clear();

 

            textBox2.Clear();

 

           

        }

    }

}

   

 


Click for details

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN

About Bahadır Şahin

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 comments:

Öne Çıkan Yayın

GridView da Seçili Satırı DetailsView da Göstermek

Merhaba arkadaşlar bu makalemizde GridView nesnesi ile birlikte DetailsView nesanesini birlikte kullanacağız. GridView da seçili satırın de...