Jump to content

C# Datagridview Bilgileri Otomatik Güncelleme


lamont
 Share

Recommended Posts

Arkadaşlar Nette Araştırdım dataGridView Kendini Otomatik Güncellemesi İçin Bir Metod Buldum Ama Hata Alıyorum Amacım Veritabanı Güncelledikten Sonra dataGridView Kendini Otomatik Yenileyip Güncel Bilgileri Göstermesini İstiyorum Kod Aşagıda 

void Listele()
{
DataContext dt = new DataContext();
dataGridView1.DataSource = dt.VeriGetir();
}
Hata Mesajı
 
'System.Data.Linq.DataContext' does not contain a constructor that takes 0 arguments
Link to comment
Share on other sites

 

Arkadaşlar Nette Araştırdım dataGridView Kendini Otomatik Güncellemesi İçin Bir Metod Buldum Ama Hata Alıyorum Amacım Veritabanı Güncelledikten Sonra dataGridView Kendini Otomatik Yenileyip Güncel Bilgileri Göstermesini İstiyorum Kod Aşagıda 

void Listele()
{
DataContext dt = new DataContext();
dataGridView1.DataSource = dt.VeriGetir();
}
Hata Mesajı
 
'System.Data.Linq.DataContext' does not contain a constructor that takes 0 arguments

 

 void Listele()
        {            
baglanti.Open();
            SqlDataAdapter data_adp = new SqlDataAdapter("Select * From tablo", baglanti);
            DataSet ds = new DataSet();
            data_adp.Fill(ds, "baglanti");
            DataTable tablo1 = new DataTable();
            data_adp.Fill(tablo1);
            dataGridView1.DataSource = tablo1;
            baglanti.Close();
}

İstediğin şey kayıt eklediğinde  datagride görüntülemekse yukarıdaki kod işini görür. 

Link to comment
Share on other sites

Kullandığım koddan bir örnek vereyim ;

        public void KAYIT_LISTELE()
        {
            SqlConnection mycon = new SqlConnection();
            SqlCommand mycommand = new SqlCommand();
            SqlDataAdapter adp = new SqlDataAdapter(mycommand);
            try
            {
                mycon.ConnectionString = Connect;
                mycon.Open();
                mycommand.Connection = mycon;
                mycommand.CommandText = "sp_Kayit_Listele";
                mycommand.CommandType = CommandType.StoredProcedure;
                DataTable dtable = new DataTable();                
                adp.Fill(dtable);                
                gridControl1.DataSource = dtable;

                gridView1.Columns["ID"].Visible = false;

                gridView1.Columns["Teklif"].Caption = "İşin Tanımı";
                gridView1.Columns["Departman"].Caption = "Departman";
                gridView1.Columns["TalepNo"].Caption = "Talep No"; 
            }
            catch (Exception e)
            {
                MessageBox.Show(Convert.ToString(e));
            }
            finally
            {
                mycon.Close();
            }
        }
Link to comment
Share on other sites

  • Editor

DataContext in constructor ı bir parametre alması gerekiyor sanırım. Yani tanımlarken.

DataContext dt = new DataContext(parametre);

 

gibi tanımlamak lazım sanırım. O parantez içerisinde ne gibi bir veri istiyor bakmak lazım.

Link to comment
Share on other sites

Olay Basitmiş Aslında Kendim Çözdüm Datagrid İçin DataTable Tanımlıyoruz Metod DataTable Global Olmalı Datagrid Temizlemek İçin Sonra Formun Activated

Olayına Clear Yapıyoruz metodu Çagrıyoruz Böylece Her Güncellemeye Bilgiler Yenileniyor Örnek Kodları Veriyorum 

 

Datagrid Formun Açılışında Veritabanındaki Bilgileri Okuyor

 

  DataTable dt = new DataTable(); // Sanal Tablomuzu Yenilemek İçin DataTable Global Tanımlıyoruz 
       public void Listele()
        {
          SqlDataAdapter oku = new SqlDataAdapter("select * from urunler", connet.bag());
            {
               
                oku.Fill(dt);
                
                dataGridView1.DataSource = dt;
               
             }
            oku.Dispose();
        }
 
daha Sonra Formun Activated Olayına Önce DataTable İçerigini Resetliyoruz Daha Sonra Metodumuzu Çagrıyoruz  Böylece DataGrid Sürekli Kendini Yeniliyor 
 
  private void Urun_Duzenle_Sil_Activated(object sender, EventArgs e)
        {
            dt.Clear(); // Sanal Tablomuzun İçerigini Temizledik 
            Listele(); // Daha Sonra Güncellenen Sanal Tablomuzu Geri Çagırdık
        }
 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...