narasiman rao

narasiman rao

  • NA
  • 519
  • 745.6k

saving the datagridview checkbox into the database.

Mar 11 2013 9:24 AM

Database design as follows;

filedname        datatype(in ms access database)

 Days             number
 course Code   text
 session1        yes/no
  ession2       yes/no
 session3        yes/no
 session4       yes/no

 My code as follows;

 save button code as follows;

    for(int i =0;i<DGv_Session.RowCount;i++)
    {
     for(int j =0;j<DGv_Session.columnCount;j++)
     {
   if(Convert.ToBoolean(DGv_Session.Rows[i].Cells[j].Value) == true)
    {
     sql = "insert into Tb_Session_Structure ([Cmn_Minor_code],[Days],[Session1],[Session2],[Session3],[Session4])";

 sql = sql + " values ('" + cb_Course_Code.Text + "','" + DGv_Session.Rows[i].Cells[0].Value.ToString() + "','" + DGv_Session.Rows[i].Cells[1].Value.ToString() + "','" + DGv_Session.Rows[i].Cells[2].Value.ToString() + "','" + DGv_Session.Rows[i].Cells[3].Value.ToString() + "','" + DGv_Session.Rows[i].Cells[4].Value.ToString() + "')";

 GFun.Error = "";
GFun.InsertAccessData(sql);
if (GFun.Error.ToString() != "")
{
MessageBox.Show(GFun.Error.ToString(), "Error");
return;
}
MessageBox.Show("Record Inserted Successfully");
}
}
}


when i rum my code and after entering the data into the datagridview and click the save button,

error shows as

Datatype mis  match in crieteria expression



Answers (1)