CafeProject.DbProcess.dbConnect C# (CSharp) Метод

dbConnect() публичный Метод

Veritabanına olan bağlantıyı açmak için kullanılan method.
public dbConnect ( ) : SqlConnection
Результат System.Data.SqlClient.SqlConnection
        public SqlConnection dbConnect()
        {
            string connectionInfo = "Data Source=.;Initial Catalog=" + dbName + ";Integrated Security=true";
            try
            {
                con = new SqlConnection(connectionInfo);
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

            }
            catch (Exception ex)
            {
                MessageBox.Show("Veritabanına bağlantı hatası: " + ex.Message);
            }
            return con;
        }

Same methods

DbProcess::dbConnect ( string ip ) : SqlConnection

Usage Example

Пример #1
0
        public void profilInsert(string adi, string soyadi, string telefon, string mail, string adres, string tcno, string notlar)
        {
            if (adi.Equals("") || soyadi.Equals("") || telefon.Equals("") || mail.Equals("") || adres.Equals("") || tcno.Equals("") || notlar.Equals(""))
            {
                MessageBox.Show("Lütfen tüm bilgileri doldurunuz.");
            }
            else if (!Regex.IsMatch(adi, @"^[ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZQWXabcçdefgğhıijklmnoöprsştuüvyzqwx]+$") || !Regex.IsMatch(soyadi, @"^[ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZQWXabcçdefgğhıijklmnoöprsştuüvyzqwx]+$"))
            {
                MessageBox.Show("Lütfen adı soyadı için sadece harf giriniz!");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox1.Focus();
            }
            else if (!Regex.IsMatch(telefon, @"^[0123456789+]+$"))
            {
                MessageBox.Show("Telefon numarası için yalnızca sayı giriniz!");
                textBox3.Text = "";
                textBox3.Focus();
            }

            else if (!IsValidEmail(textBox4.Text))
            {
                MessageBox.Show("Hatalı formatta mail adresi girdiniz!");
                textBox4.Text = "";
                textBox4.Focus();
            }
            else if (textBox6.TextLength < 11 || textBox6.TextLength > 11)
            {
                MessageBox.Show("Tc kimlik numarası hatalı!");
                textBox6.Text = "";
                textBox6.Focus();
            }
            else
            {
                SqlCommand com = new SqlCommand("profilInsert", db.dbConnect());
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.Add("@adi", SqlDbType.VarChar, 255).Value     = adi;
                com.Parameters.Add("@soyadi", SqlDbType.VarChar, 255).Value  = soyadi;
                com.Parameters.Add("@telefon", SqlDbType.VarChar, 255).Value = telefon;
                com.Parameters.Add("@mail", SqlDbType.VarChar, 255).Value    = mail;
                com.Parameters.Add("@adres", SqlDbType.VarChar, 500).Value   = adres;
                com.Parameters.Add("tcno", SqlDbType.VarChar, 11).Value      = tcno;
                com.Parameters.Add("notlar", SqlDbType.VarChar, 500).Value   = notlar;
                db.dbConnect();
                com.ExecuteNonQuery();
                db.dbClose();
                li.Clear();
                idTut();

                MessageBox.Show("Profil Kaydı Yapıldı");
            }
            db.dbConnect();
            int        i    = Convert.ToInt32(li[li.Count - 1]);
            SqlCommand com1 = new SqlCommand("insert into kullanicilar(profilID) values (@id)", db.dbConnect());

            com1.Parameters.AddWithValue("@id", i);
            com1.ExecuteNonQuery();
            db.dbClose();
        }
All Usage Examples Of CafeProject.DbProcess::dbConnect