MySql Database de Arama ve Arama Sonucunu dataGridView da Göstermek

 

Merhaba arkadaşlar bu makalemizde MySql veritabanında kayıt aramayı göreceğiz. İlk öncde Mysql veritabanında person tablosunu oluşturuyoruz. Sonra textBox a girilen adı person tablosunda arayacağız. Arama sonucunu dataGridView de göstereceğiz.


 

 








Şekil 1


 










Şekil 2

 

Form1.cs

 

 

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 MySql.Data;

using MySql.Data.MySqlClient;

 

namespace mysql_search

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void btnSearch_Click(object sender, EventArgs e)

        {

            MySqlConnection con = new MySqlConnection("Server=localhost;Database=dbemployee;Uid=root;Pwd='2344';AllowUserVariables=True;UseCompression=True;");

            con.Open();

            MySqlCommand cmd = new MySqlCommand("Select * From person Where Name= '" + textBox1.Text + "'" , con);

            MySqlDataAdapter da = new MySqlDataAdapter(cmd);

            DataSet ds = new DataSet();

            da.Fill(ds);

            con.Close();

            dataGridView1.DataSource = ds.Tables[0];

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            MySqlConnection con = new MySqlConnection("Server=localhost;Database=dbemployee;Uid=root;Pwd='2344';AllowUserVariables=True;UseCompression=True;");

            con.Open();

            MySqlCommand cmd = new MySqlCommand("Select * From person", con);

            MySqlDataAdapter da = new MySqlDataAdapter(cmd);

            DataSet ds = new DataSet();

            da.Fill(ds);

            con.Close();

            dataGridView1.DataSource = ds.Tables[0];

        }

    }

}

 

 

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...