Click here to Skip to main content
16,017,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I'm importing data from excel to datagridview. Initially I'm bind the dataset to DGV. When I'm importing I'm checking whether the imported item is already existing in dataset if not available I'm adding the row to DS and then binding. I want to highlight the imported data from excel in DGV from those which is already existing at the time of import, how can I achieve this, can anyone help me,
Here is what Ive done so far

workbook = excelApp.Workbooks.Open(filename, 0, true, 5, "", "", true,
                        Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                    worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets.get_Item(1);
                    range = worksheet.UsedRange;
                    Array myValues = (Array)range.Cells.Value2;
                    int vertical = myValues.GetLength(0);
                    int horizontal = myValues.GetLength(1);
                    workbook.Close(true, null, null);
                    excelApp.Quit();
                    releaseObject(workbook);
                    releaseObject(worksheet);
                    releaseObject(excelApp);
                    for (int i = 1; i <= horizontal; i++)
                    {
                        DataRow objdr = dsobbtemp.Tables[0].NewRow();
                        objdr["objectRevisedName"] = myValues.GetValue(1, i).ToString();
                        srowFilter = "objectRevisedName = '" + objdr["objectRevisedName"].ToString() + "'";
                        if (dsobbtemp.Tables[0].Select(srowFilter).Length == 0)
                        {
                            dsobbtemp.Tables[0].Rows.Add(objdr);
                        }
                    }
                    objdt = dsobbtemp.Tables[0].GetChanges();
                    for (int i = 0; i < objdt.Rows.Count; i++)
                    {
                        SqlParameter[] sqlparam1 = {
                                                      new SqlParameter("@accountID",iaccountID),                                                  };
                        DBAccess objDBaccess = new DBAccess();
                        iResults = objDBaccess.ExecuteCommand("AddData", sqlparam1);

Thanks in Advance
Posted

1 solution

Use the OnRowDataBound event in the GridView
 
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