Marvin kakuru

Marvin kakuru

  • 1.1k
  • 355
  • 160.1k

save data in percentage format

Mar 18 2013 9:41 AM

Hi everyone,

I hope your alright. I am having a problem saving a percentage value to a percentage set column in my access database, below is the code im using the "perage" column of my datagridview2 is the percentage column, currently im getting a wrong format error. 

 

OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\katoto\Documents\Visual Studio 2010\Projects\Genesis Philcollins\Genesis Philcollins\bin\Debug\thyfarm.accdb;Jet OLEDB:Database Password=Kyozi");

            cn.Open();

 

            foreach (DataGridViewRow row in dataGridView2.Rows)

            {

              

                if (row.IsNewRow) break;

                int wkno = Int32.Parse(label4.Text.ToString());

                int year = Int32.Parse(label28.Text.ToString());

                DateTime date = DateTime.Parse(textBox16.Text.ToString());

               

                int exp = Int32.Parse(row.Cells["codeid"].Value.ToString());

                int per = Int32.Parse(row.Cells["perage"].Value.ToString());         

               Decimal per = Decimal.Parse(row.Cells["perage"].Value.ToString());

string insertString = " insert into dihengericosanalysis (dat,wkno,mont,yr,codeid,code,sumofdebit,avgofsumofcost,perage) values (#" + date.ToString("MM/dd/yyyy") + "# , " + wkno.ToString() + " , '" + label27.Text + "' , " + year.ToString() + " ," + exp.ToString() + ", '" + row.Cells["code"].Value + "' , '" + row.Cells["sumofdebit"].Value + "' , '" + row.Cells["avgofsumofcost"].Value + "', " + row.Cells["perage"].Value + ")";

                OleDbCommand cmd = new OleDbCommand(insertString, cn);

                cmd.ExecuteNonQuery();

 

            }

            cn.Close();

 

any help will be greatly appreciated.

Kind regards.

 


Answers (1)