C# Veritabanında Veri Varmı Yokmu Kontrolu

//Veritabanında varmı yokmu kontrolu yapılıyor...
            //Farklı bir bloga girmeden farklı bağlantı Kullanılamaz...
            SqlConnection baglanticek = new SqlConnection(cs1);

            SqlCommand tcvergicek = new SqlCommand("SELECT *FROM musteri_iletisim where tcno_vergino_ref ='" + tcvergiTextBox1.Text.ToString() + "'", baglanticek);
            baglanticek.Open();
            int tcvergicekcount = 0;
            SqlDataReader dr = tcvergicek.ExecuteReader();
            while (dr.Read())
            {
                tcvergicekcount++;
            }
            dr.Close();
            baglanticek.Close();

            SqlCommand epostacek = new SqlCommand("SELECT *FROM musteri_iletisim where eposta ='" + TextBox2.Text.ToString() + "'", baglanticek);
            baglanticek.Open();
            int epostacekcount = 0;
            SqlDataReader dr2 = epostacek.ExecuteReader();
            while (dr2.Read())
            {
                epostacekcount++;
            }
            dr2.Close();
            baglanticek.Close();

            SqlCommand telefoncek = new SqlCommand("SELECT *FROM musteri_iletisim where telefon ='" + TextBox5.Text.ToString() + "'", baglanticek);
            baglanticek.Open();
            int telefoncekcount = 0;
            SqlDataReader dr3 = telefoncek.ExecuteReader();
            while (dr3.Read())
            {
                telefoncekcount++;
            }
            dr3.Close();
            baglanticek.Close();



         

            if (tcvergiTextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "" || TextBox4.Text == "" || TextBox5.Text == "")
            {
                Label1.Text = "Boş Alan Bırakmayınız...";
                Label1.ForeColor = System.Drawing.Color.White;
                Label1.CssClass = "lblstyleuyari";

            }
               


            else if(TextBox3.Text!=TextBox4.Text)
              {
                         Label1.Text = "Şifreler Uyuşmuyor..";
                         Label1.ForeColor = System.Drawing.Color.White;
                         Label1.CssClass = "lblstyleuyari";
             }
            else if (tcvergicekcount != 0)
             {
                        Label1.Text = "TCNO/VERGİNO Kontrol Ediniz";
                        Label1.ForeColor = System.Drawing.Color.White;
                        Label1.CssClass = "lblstyleuyari";
             }
            else if (epostacekcount != 0)
             {
                        Label1.Text = "E-mail Kontrol Ediniz";
                        Label1.ForeColor = System.Drawing.Color.White;
                        Label1.CssClass = "lblstyleuyari";
             }
            else if (telefoncekcount != 0)
            {
                        Label1.Text = "Telefon No Kontrol Ediniz";
                        Label1.ForeColor = System.Drawing.Color.White;
                        Label1.CssClass = "lblstyleuyari";
            }
                
           else
            {
                        SqlConnection baglanti = new SqlConnection(cs1);

                        try
                        {
                            getIP();
                            if (baglanti.State == ConnectionState.Closed)
                                baglanti.Open();

                            string kayit = "INSERT INTO musteri_iletisim(tcno_vergino_ref,eposta,sifre,telefon,musterionay,ipadresi) values (@tcno_vergino,@ep,@sif,@tel,@mo,@ip)";

                            SqlCommand komut = new SqlCommand(kayit, baglanti);
                            komut.Parameters.AddWithValue("@tcno_vergino", tcvergiTextBox1.Text);
                            komut.Parameters.AddWithValue("@ep", TextBox2.Text);
                            komut.Parameters.AddWithValue("@sif", TextBox3.Text);
                            komut.Parameters.AddWithValue("@tel", TextBox5.Text);
                            komut.Parameters.AddWithValue("@mo", "False");
                            komut.Parameters.AddWithValue("@ip", IPadresi);

                            komut.ExecuteNonQuery();
                            baglanti.Close();

                            Label1.Text = "Başarılı";
                            Label1.ForeColor = System.Drawing.Color.White;
                            Label1.CssClass = "lblstyleonay";
                            Label1.Font.Bold = true;

                            HtmlMeta mta = new HtmlMeta();
                            mta.HttpEquiv = "Refresh";
                            mta.Content = "2;url=giris.aspx";
                            this.Page.Controls.Add(mta);

                        }
                        catch (Exception hata)
                        {
                            Label1.Text = "Başarısız";
                            Label1.ForeColor = System.Drawing.Color.White;
                            Label1.CssClass = "lblstyleuyari";
                        }
                
                   }
               }
          }

Hiç yorum yok:

Yorum Gönder