Click here to Skip to main content
15,887,854 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to Open the Docx File in Silverlight Pin
Brisingr Aerowing24-Apr-15 6:31
professionalBrisingr Aerowing24-Apr-15 6:31 
AnswerRe: How to Open the Docx File in Silverlight Pin
Mycroft Holmes24-Apr-15 13:35
professionalMycroft Holmes24-Apr-15 13:35 
GeneralRe: How to Open the Docx File in Silverlight Pin
Hrishikesh Shivacharan6-May-15 21:20
Hrishikesh Shivacharan6-May-15 21:20 
GeneralRe: How to Open the Docx File in Silverlight Pin
Mycroft Holmes6-May-15 22:10
professionalMycroft Holmes6-May-15 22:10 
QuestionAdmin questions about Microsoft exam 70-483 Pin
CRobert45623-Apr-15 4:57
CRobert45623-Apr-15 4:57 
AnswerRe: Admin questions about Microsoft exam 70-483 Pin
Dave Kreskowiak23-Apr-15 9:39
mveDave Kreskowiak23-Apr-15 9:39 
GeneralRe: Admin questions about Microsoft exam 70-483 Pin
Mycroft Holmes23-Apr-15 12:56
professionalMycroft Holmes23-Apr-15 12:56 
QuestionHow to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell23-Apr-15 4:33
Norris Chappell23-Apr-15 4:33 
C#
if (this.DataCenterLaborFileUpload.HasFile)
             {
                 var extension = Path.GetExtension(DataCenterLaborFileUpload.FileName);
                 string currentName = "";
                decimal currentHours = 0.00M;
                 decimal currentFTE = 0.00M;
                 string ResourceName = "";

                if (extension == ".csv")
                 {
                     StreamReader csvreader = new StreamReader(DataCenterLaborFileUpload.FileContent);
                     DataTable dt = new DataTable();
                     dt.Columns.Add("txtName");
                     dt.Columns.Add("txtHours");
                     dt.Columns.Add("txtFTE");

                    while (!csvreader.EndOfStream)
                     {
                         DataRow dr = dt.NewRow();

                        var line = csvreader.ReadLine();
                         var values = line.Split(',');

                        if (values[0].Trim() != "Pers.No.")
                         {

                            using (DbConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString))
                             {
                                 conn.Open();
                                 using (DbCommand cmd = conn.CreateCommand())
                                 {
                                     cmd.Connection = conn;
                                     cmd.CommandText = "SELECT ResourceName FROM StaffTracking  order by PersonnelResourceType, ResourceName";
                                  //   DbParameter p1 = cmd.CreateParameter();
                                  //   p1.ParameterName = "restype";
                                  //   p1.Value = "Supplier";
                                  //   cmd.Parameters.Add(p1);
                                     using (DbDataReader row = cmd.ExecuteReader())
                                     {
                                         while (row.Read())
                                         {


                                             ResourceName = row.GetString(0);
                                             //            }
                                             //        }
                                             //    }
                                             //}
                                             if (ResourceName != (values[1].Trim()))
                                             {


                                                 if (values[1].Trim() == currentName)
                                                 {

                                                    currentHours = currentHours + Convert.ToDecimal(values[9].Trim());

                                                }
                                                 else
                                                 {
                                                     if (currentName == "")
                                                     {
                                                         dr["txtName"] = currentName;
                                                         dr["txtHours"] = currentHours;
                                                         dr["txtFTE"] = currentFTE + Math.Round(currentHours / (weekdaysInMonth() * 8), 2);


                                                         dt.Rows.Add(dr);
                                                         dt.AcceptChanges();


                                                     }
                                                     
                                                         currentHours = Convert.ToDecimal(values[9].Trim());
                                                         currentName = values[1].Trim();
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }

                    DataRow drfinal2 = dt.NewRow();
                     drfinal2["txtName"] = currentName;
                     drfinal2["txtHours"] = currentHours;
                     drfinal2["txtFTE"] = currentFTE + Math.Round(currentHours / (weekdaysInMonth() * 8), 2);
                     dt.Rows.Add(drfinal2);
                     dt.AcceptChanges();


                     gvDataCenterLabor.DataSource = dt;

                }


                 gvDataCenterLabor.DataBind();

                //     Page.DataBind();
             }

        }



Here is my csv file:



Pers.No. Name HomeFID Copy Range/Value from Column V Worked Date Job Code Account Pay Type Activity Type Hours
11111111 Doe Jane USA7064810 US1-08333.01.08.02.03 20150223 00S15H 9.61E+09 410 8
11111111 Doe John USA7064810 US1-08333.01.08.02.03 20150210 00S15H 9.61E+09 410 9
11111111 Smith Jane USA7064810 US1-08333.01.08.02.03 20150226 00S15H 9.61E+09 410 8


So if Doe Jane is not in the SQL table I would like to only display her.

It's only displaying the ones from the CSV file that are in the SQL Table.
AnswerRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre23-Apr-15 4:49
professionalSascha Lefèvre23-Apr-15 4:49 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell23-Apr-15 5:44
Norris Chappell23-Apr-15 5:44 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre23-Apr-15 5:56
professionalSascha Lefèvre23-Apr-15 5:56 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell23-Apr-15 6:20
Norris Chappell23-Apr-15 6:20 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Kevin Marois23-Apr-15 6:37
professionalKevin Marois23-Apr-15 6:37 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre23-Apr-15 6:55
professionalSascha Lefèvre23-Apr-15 6:55 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell23-Apr-15 13:21
Norris Chappell23-Apr-15 13:21 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre24-Apr-15 3:00
professionalSascha Lefèvre24-Apr-15 3:00 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell24-Apr-15 5:25
Norris Chappell24-Apr-15 5:25 
AnswerRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre24-Apr-15 11:04
professionalSascha Lefèvre24-Apr-15 11:04 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell24-Apr-15 11:57
Norris Chappell24-Apr-15 11:57 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre24-Apr-15 12:56
professionalSascha Lefèvre24-Apr-15 12:56 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell25-Apr-15 13:28
Norris Chappell25-Apr-15 13:28 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre25-Apr-15 13:42
professionalSascha Lefèvre25-Apr-15 13:42 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell25-Apr-15 13:50
Norris Chappell25-Apr-15 13:50 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre25-Apr-15 14:02
professionalSascha Lefèvre25-Apr-15 14:02 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell25-Apr-15 14:08
Norris Chappell25-Apr-15 14:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.