Skip to content

Saving the datagridview checkbox into the database.

narasiman rao

Asked Mar 11, 2013, 5:24 AM EDT1 answer
Share
LinkedInX
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

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Vishal Gilbile
    0
    Hi there,
               From my point of view what i can see that your first column i.e. Course_Code accepts value as a number and when you are passing the value you are passing it as a string (cb_Course_Code.Text). Try to convert it as a number by using Convert class.

    For eg Convert.ToInt32(cb_Course_Code.Text).


    Hope that solves your problem.

    With Regards,
    Vishal Gilbile.
    0