Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi friends.
I preparing School Note in Datagridview by Access database mdb

I have 50 fields.. But I want to see on datagridview only 13 fields..
Default "Note" fields default value "0" enter in Microsoft Access.. Because I want to collect 12 numbers Notes and print total in datagridview TOTAL COLUMN. This fields all INTEGER in my Access database...

My DbGrid View columns not add on dataviewgrid .. I added with code only 13 column... you will see this code bottom...

I want UPDATE my database this Note numbers and total data .. But I cant.. always said UPDATED but cant see this datas in my database...

how I can do it? thanks...




This code here....

C#
private void verilerigoster_butun_ogrenciler()
       {


           lblbaslik.Text = "Bütün Sınıflar 1. Sınav Not Girişi";

           baglan.Open();
           ds.Tables.Clear();
           da = new OleDbDataAdapter("Select [ogrno], [adsoyad], [sinif], [1sorupuan1], [1sorupuan2], [1sorupuan3], [1sorupuan4], [1sorupuan5], [1sorupuan6], [1sorupuan7], [1sorupuan8], [1sorupuan9], [1sorupuan10], [1sorupuan11], [1sorupuan12], [toplampuan1], [derece1] from tarih order by sinif", baglan);
           da.Fill(ds, "tarih");
           dataGridView1.DataSource = ds.Tables[0];
           baglan.Close();

           da.Dispose();


           label1.Text = "Bütün Sınıflar";
           label2.Text = "Bütün Sınıflar";
           label3.Text = "Bütün Sınıflar";
           label4.Text = "Bütün Sınıflar";
           label5.Text = "Bütün Sınıflar";
           label6.Text = "Bütün Sınıflar";
           label7.Text = "Bütün Sınıflar";
           label8.Text = "Bütün Sınıflar";
           label9.Text = "Bütün Sınıflar";
           label10.Text = "Bütün Sınıflar";
           label11.Text = "Bütün Sınıflar";
           label12.Text = "Bütün Sınıflar";








           //En son eklenen boş satırı gizleme kodu
           dataGridView1.AllowUserToAddRows = false;

           // Sütun genişliklerini ayarlama

           dataGridView1.Columns[0].Width = 100;
           dataGridView1.Columns[1].Width = 200;
           dataGridView1.Columns[2].Width = 100;
           dataGridView1.Columns[3].Width = 50;
           dataGridView1.Columns[4].Width = 50;
           dataGridView1.Columns[5].Width = 50;
           dataGridView1.Columns[6].Width = 50;
           dataGridView1.Columns[7].Width = 50;
           dataGridView1.Columns[8].Width = 50;
           dataGridView1.Columns[9].Width = 50;
           dataGridView1.Columns[10].Width = 50;
           dataGridView1.Columns[11].Width = 50;
           dataGridView1.Columns[12].Width = 50;
           dataGridView1.Columns[13].Width = 50;
           dataGridView1.Columns[14].Width = 50;
           dataGridView1.Columns[15].Width = 100;
           dataGridView1.Columns[16].Width = 150;

           //Sütun adı değiştirme
           dataGridView1.Columns[0].HeaderText = "ÖğrNo";
           dataGridView1.Columns[1].HeaderText = "Ad-Soyad";
           dataGridView1.Columns[2].HeaderText = "Sınıf";
           dataGridView1.Columns[3].HeaderText = "1";
           dataGridView1.Columns[4].HeaderText = "2";
           dataGridView1.Columns[5].HeaderText = "3";
           dataGridView1.Columns[6].HeaderText = "4";
           dataGridView1.Columns[7].HeaderText = "5";
           dataGridView1.Columns[8].HeaderText = "6";
           dataGridView1.Columns[9].HeaderText = "7";
           dataGridView1.Columns[10].HeaderText = "8";
           dataGridView1.Columns[11].HeaderText = "9";
           dataGridView1.Columns[12].HeaderText = "10";
           dataGridView1.Columns[13].HeaderText = "11";
           dataGridView1.Columns[14].HeaderText = "12";
           dataGridView1.Columns[15].HeaderText = "Toplam";
           dataGridView1.Columns[16].HeaderText = "Derece";<<br mode="hold" />}

Private Void Total()
{

OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Visual Studio Projects\\OZGUR_OKUL\\Classes.mdb");


int ogr = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString());

            int a1 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[3].Value);
            int a2 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[4].Value);
            int a3 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[5].Value);
            int a4 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[6].Value);
            int a5 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[7].Value);
            int a6 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[8].Value);
            int a7 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[9].Value);
            int a8 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[10].Value);
            int a9 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[11].Value);
            int a10 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[12].Value);
            int a11 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[13].Value);
            int a12 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[14].Value);
            int atoplam = Convert.ToInt32(dataGridView1.CurrentRow.Cells[15].Value);

 baglan.Open();

        OleDbCommand guncelle = new OleDbCommand("UPDATE tarih SET 1sorupuan1 = @3, 1sorupuan2 =@4 , 1sorupuan3 =@5, 1sorupuan4 = @6, 1sorupuan5 = @7, 1sorupuan6 = @8, 1sorupuan7 = @9, 1sorupuan8 = @10, 1sorupuan9 = @11, 1sorupuan10 = @12, 1sorupuan11 = @13, 1sorupuan12 = @14, toplampuan1 = @15 where ogrno = '" + ogr + "'", baglan);
                    guncelle.Parameters.AddWithValue("@3", a1);
                    guncelle.Parameters.AddWithValue("@4", a2);
                    guncelle.Parameters.AddWithValue("@5", a3);
                    guncelle.Parameters.AddWithValue("@6", a4);
                    guncelle.Parameters.AddWithValue("@7", a5);
                    guncelle.Parameters.AddWithValue("@8", a6);
                    guncelle.Parameters.AddWithValue("@9", a7);
                    guncelle.Parameters.AddWithValue("@10", a8);
                    guncelle.Parameters.AddWithValue("@11", a9);
                    guncelle.Parameters.AddWithValue("@12", a10);
                    guncelle.Parameters.AddWithValue("@13", a11);
                    guncelle.Parameters.AddWithValue("@14", a12);
                    guncelle.Parameters.AddWithValue("@15", atoplam);
                    guncelle.ExecuteNonQuery();*/

            cb = new OleDbCommandBuilder(da);
            da.Update(dt);
}


private void Sinav1_Load(object sender, EventArgs e)
       {

   
               baglan.Open();

               da = new OleDbDataAdapter("Select [ogrno], [adsoyad], [sinif], [1sorupuan1], [1sorupuan2], [1sorupuan3], [1sorupuan4], [1sorupuan5], [1sorupuan6], [1sorupuan7], [1sorupuan8], [1sorupuan9], [1sorupuan10], [1sorupuan11], [1sorupuan12], [toplampuan1], [derece1] from tarih order by sinif";, baglan);
               dt = new DataTable();
               da.Fill(dt);
               dataGridView1.DataSource = dt;

}



              baglan.Close();
Posted
Updated 15-May-15 15:37pm
v3
Comments
Gerhard_Louis 16-May-15 3:05am    
When using OledbDataAdapter it opens the connection to the database when you pass the connection string :,baglan so baglan.Open() is not needed.

Why do you clear the Tables?
Create a new DataTable eg: DataTable dt;


in your private void verilerigoster_butun_ogrenciler()
dt = ds.Tables["tarih"]
this.da.Fill(ds,"tarih");
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "tarih";

I just think you have to re look the way you want interact databases through Oledb
Gerhard_Louis 16-May-15 3:42am    
[toplampuan1], [derece1] are joint tables?

No joint all fields one table
 
Share this answer
 
ı create table with dt but UPDATE command cant work... changed filed on datagridview but cant apply on my database
 
Share this answer
 
Comments
Gerhard_Louis 17-May-15 0:56am    
Your update should be something like this

OleDbCommand guncelle = new OleDbCommand("UPDATE tarih SET 1sorupuan1 = @3, 1sorupuan2 =@4 , 1sorupuan3 =@5, 1sorupuan4 = @6, 1sorupuan5 = @7, 1sorupuan6 = @8, 1sorupuan7 = @9, 1sorupuan8 = @10, 1sorupuan9 = @11, 1sorupuan10 = @12, 1sorupuan11 = @13, 1sorupuan12 = @14, toplampuan1 = @15 where ogrno = '" + ogr + "'", baglan);
guncelle.Parameters.AddWithValue("@3", a1);
guncelle.Parameters.AddWithValue("@4", a2);
guncelle.Parameters.AddWithValue("@5", a3);
guncelle.Parameters.AddWithValue("@6", a4);
guncelle.Parameters.AddWithValue("@7", a5);
guncelle.Parameters.AddWithValue("@8", a6);
guncelle.Parameters.AddWithValue("@9", a7);
guncelle.Parameters.AddWithValue("@10", a8);
guncelle.Parameters.AddWithValue("@11", a9);
guncelle.Parameters.AddWithValue("@12", a10);
guncelle.Parameters.AddWithValue("@13", a11);
guncelle.Parameters.AddWithValue("@14", a12);
guncelle.Parameters.AddWithValue("@15", atoplam);

this.da.UpdateCommand = guncelle;
this.da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
this.da.Update(ds, ""tarih");
this.ds.AcceptChanges();
baglan.close();
Gerhard_Louis 17-May-15 1:01am    
edit this.da.Update(ds, "tarih");
I written but cant. My fields always empty
 
Share this answer
 
Additional information: TableMapping['tarih'] or DataTable 'tarih' not found by UPDATE. Error gived me
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900