Click here to Skip to main content
15,894,955 members
Home / Discussions / C#
   

C#

 
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 16:26
Norris Chappell25-Apr-15 16:26 
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 16:27
Norris Chappell25-Apr-15 16:27 
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 16:36
professionalSascha Lefèvre25-Apr-15 16:36 
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 16:40
Norris Chappell25-Apr-15 16:40 
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 16:46
professionalSascha Lefèvre25-Apr-15 16:46 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell27-Apr-15 3:53
Norris Chappell27-Apr-15 3:53 
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èvre27-Apr-15 5:08
professionalSascha Lefèvre27-Apr-15 5: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 Chappell27-Apr-15 10:53
Norris Chappell27-Apr-15 10:53 
I tried to pass as an argument but getting errors:
c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES\StaffingWebParts\VisualWebPart1\VisualWebPart1UserControl.ascx(13): error CS0117: 'ASP._controltemplates_staffingwebparts_visualwebpart1_visualwebpart1usercontrol_ascx' does not contain a definition for 'ImportButton_Click'
I need protected void ImportButton_Click(object sender, EventArgs e) somewhere but not sure where?

using ( StreamReader reader = new StreamReader(NewResourceFileUpload.FileContent))

using System;
using System.Configuration;
using System.Data;
using System.IO;
using System.Data.Common;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Globalization;

namespace StaffingWebParts.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
     

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
          //      this.QueryStaff();
                gvNewResource.DataSource = QueryStaff();
                gvNewResource.DataBind();
                           
            }
        }
       
        private static char[] Colon = new char[] { ',' };
        private DataTable QueryStaff()
        {
            const int nameColumnIndex = 1;
            const int hoursColumnIndex = 9;
                 
                
                
            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString))
            using (var cmd = new SqlCommand("", conn))
            using (var dataAdapter = new SqlDataAdapter(cmd))
            using (var cmdBuilder = new SqlCommandBuilder(dataAdapter))
            {
                // create temporary table in database
               conn.Open();
               cmd.CommandText = "CREATE TABLE #TempTable(Name nvarchar(100) NOT NULL, Hours decimal(6, 2) NOT NULL);";
               cmd.ExecuteNonQuery();

                // create a DataTable and let the DataAdapter create appropriate columns for it
                DataTable dataTable = new DataTable();
                cmd.CommandText = "SELECT * FROM #TempTable;";
                dataAdapter.Fill(dataTable);

                // read the CSV-records into the DataTable
                dataTable.BeginLoadData();
         
           using ( StreamReader reader = new StreamReader(NewResourceFileUpload.FileContent))
                      
          
            //    using (StreamReader reader = File.OpenText(@"c:\Users\pzd74f\Downloads\FinalLabor2015.csv"))
                {
                    string line;
                    if (reader.ReadLine() != null) // skip first line (headers)
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            string[] columns = line.Split(Colon, StringSplitOptions.None);

                            DataRow row = dataTable.NewRow();
                            row["Name"] = columns[nameColumnIndex];
                            row["Hours"] = Decimal.Parse(columns[hoursColumnIndex], NumberFormatInfo.InvariantInfo);
                            dataTable.Rows.Add(row);
                          
                        }
                        
                    }
                }
                dataTable.EndLoadData();
          
                // insert the records from the DataTable into the temporary table
                dataAdapter.Update(dataTable);
         
                // load the result of the "main purpose" query into the DataTable
                dataTable.Clear();
                cmd.CommandText = "SELECT Tmp.Name, SUM(Tmp.Hours) FROM #TempTable AS Tmp WHERE NOT EXISTS (SELECT * FROM StaffTracking AS ST WHERE Tmp.Name = ST.ResourceName) GROUP BY Tmp.Name;";
                dataAdapter.Fill(dataTable);
               
               
                return dataTable;
            }
            
        }
    
    }
}

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èvre27-Apr-15 11:16
professionalSascha Lefèvre27-Apr-15 11:16 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell27-Apr-15 11:40
Norris Chappell27-Apr-15 11:40 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell28-Apr-15 5:40
Norris Chappell28-Apr-15 5:40 
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èvre28-Apr-15 7:27
professionalSascha Lefèvre28-Apr-15 7:27 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell28-Apr-15 9:00
Norris Chappell28-Apr-15 9: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 Chappell28-Apr-15 10:12
Norris Chappell28-Apr-15 10:12 
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èvre28-Apr-15 10:16
professionalSascha Lefèvre28-Apr-15 10:16 
Questioninserire il dato nel database access (senza generare uno nuovo) Pin
Member 1161509923-Apr-15 3:22
Member 1161509923-Apr-15 3:22 
AnswerRe: inserire il dato nel database access (senza generare uno nuovo) Pin
Pete O'Hanlon23-Apr-15 3:24
mvePete O'Hanlon23-Apr-15 3:24 
GeneralRe: inserire il dato nel database access (senza generare uno nuovo) Pin
Member 1161509924-Apr-15 1:01
Member 1161509924-Apr-15 1:01 
AnswerRe: inserire il dato nel database access (senza generare uno nuovo) Pin
Richard Deeming23-Apr-15 9:32
mveRichard Deeming23-Apr-15 9:32 
QuestionUnable to load DLL "dllforvc.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E). Pin
Member 1159873923-Apr-15 1:27
Member 1159873923-Apr-15 1:27 
AnswerRe: Unable to load DLL "dllforvc.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E). Pin
Pete O'Hanlon23-Apr-15 1:37
mvePete O'Hanlon23-Apr-15 1:37 
GeneralRe: Unable to load DLL "dllforvc.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E). Pin
Member 1159873923-Apr-15 22:36
Member 1159873923-Apr-15 22:36 
GeneralRe: Unable to load DLL "dllforvc.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E). Pin
Pete O'Hanlon23-Apr-15 22:58
mvePete O'Hanlon23-Apr-15 22:58 
Questionconvert code form C# 2008 to C# 2005 have DataClass ? Pin
Member 245846722-Apr-15 20:32
Member 245846722-Apr-15 20:32 
AnswerRe: convert code form C# 2008 to C# 2005 have DataClass ? Pin
OriginalGriff22-Apr-15 21:42
mveOriginalGriff22-Apr-15 21:42 

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.