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

C#

 
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 
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 
Hi Sascha,

You have been quite helpful. I have redone my code and now using "where not exists" code and it is working. However, the temporary table is not updated with the csv file yet. I read the article you recommended. I not sure how to put it in my code? I don't need the FTE only the name. I don't think I will need the hours but since the file have several rows with the same name it wouldn't be bad to sum up the hours too. Once I can update the table with the csv file, I think I will be done.

Thanks,

Norris

I forgot to include my code:
C#
using System;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace StaffingWebParts.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
       public SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("Name");
                
                SqlDataReader myReader = null;
                SqlCommand cmd = new SqlCommand("select Name FROM [SP2010_EDCStaffing_AppDB].[dbo].[Tempname] where not exists (select * FROM [SP2010_EDCStaffing_AppDB].[dbo].StaffTracking WHERE tempname.Name = Stafftracking.ResourceName)");            
                         
                cmd.Connection = conn;
                conn.Open();
                myReader = cmd.ExecuteReader();
                while (myReader.Read())
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = myReader["Name"].ToString();
                                                 
                    dt.Rows.Add(dr);
                }
                          
                GridView1.DataSource = dt;
                GridView1.DataBind();
                conn.Close();
            }
        }
       
      }
    }

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 
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:11
Norris Chappell25-Apr-15 14:11 
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:13
Norris Chappell25-Apr-15 14:13 
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 15:11
professionalSascha Lefèvre25-Apr-15 15:11 
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 15:28
Norris Chappell25-Apr-15 15:28 
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 15:35
Norris Chappell25-Apr-15 15:35 
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 15:41
professionalSascha Lefèvre25-Apr-15 15:41 
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 15:47
Norris Chappell25-Apr-15 15:47 

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.