Rivaldo Grenz

Rivaldo Grenz

  • NA
  • 8
  • 53.9k

problem updating data in a datagridview through a query update in access database 2007?

Oct 8 2010 10:59 PM

Hello

I need your help, I am developing an app in C# using an Access database(2007), the problem I think is the query update, I have searched over internet but nothing works, I have a datagridview and It has 3 columns the user needs to puts data to the last 2 columns(5 rows), I already do it but when I fill the columns in the datagridview It doenst store the data in the database access. So please I need you help this is my code, help very apreciated :D


 private void btnGuardar_Click(object sender, EventArgs e)
   
{

       
//using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Databsename.accdb"))
       
//{

       
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Databasename.accdb;Persist Security Info=false");


       
int grade = 1;
       
string x;
       
string comment;

           
for (int i = 0; i < this.dataGridView4.Rows.Count-1; i++)
           
{

                x
= dataGridView4.Rows[i].Cells[1].Value.ToString();
               
//Console.WriteLine(x);
               
MessageBox.Show(x);

                grade
= int.Parse(x);


                comment
= dataGridView4.Rows[i].Cells[2].Value.ToString();
               
MessageBox.Show(comment);

               
OleDbCommand cmd = new OleDbCommand("Update archievemnet set grade= @GRADE comment=@COMMENT WHERE idLine =1  ", conn);

                cmd
.Parameters.Add(new OleDbParameter("@GRADE", OleDbType.Integer));
                cmd
.Parameters["@GRADE"].Value = grade;

                cmd
.Parameters.Add(new OleDbParameter("@comment", OleDbType.VarChar));
                cmd
.Parameters["@COMMENT"].Value = comment;

                cmd
.Connection.Open();
                cmd
.ExecuteNonQuery();
                cmd
.Connection.Close();
           
}



       
//}



   
}


Answers (1)