Click here to Skip to main content
15,900,461 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionWhile implementing interface concept in asp.net web application getting an error - Internal Compiler Error: stage 'DEFINE' Pin
Member 110118531-May-15 20:13
Member 110118531-May-15 20:13 
AnswerRe: While implementing interface concept in asp.net web application getting an error - Internal Compiler Error: stage 'DEFINE' Pin
F-ES Sitecore2-May-15 1:19
professionalF-ES Sitecore2-May-15 1:19 
Questiondynamically insert textbox in gridview and insert the data of textbox in database Pin
Praveen Kandari30-Apr-15 23:13
Praveen Kandari30-Apr-15 23:13 
AnswerRe: dynamically insert textbox in gridview and insert the data of textbox in database Pin
Arun Banik2-May-15 3:17
Arun Banik2-May-15 3:17 
QuestionPraser Error Pin
Member 1093739330-Apr-15 1:23
Member 1093739330-Apr-15 1:23 
AnswerRe: Praser Error Pin
F-ES Sitecore30-Apr-15 2:17
professionalF-ES Sitecore30-Apr-15 2:17 
SuggestionRe: Praser Error Pin
ZurdoDev30-Apr-15 5:34
professionalZurdoDev30-Apr-15 5:34 
QuestionHow do I access a csv file without hardcoding it in my code? Pin
Norris Chappell29-Apr-15 15:09
Norris Chappell29-Apr-15 15:09 
I want to use:
using (StreamReader reader = new StreamReader(NRFileUpload.FileContent))
instead of
using (StreamReader reader = File.OpenText(@"c:\Users\pzd74f\Downloads\FinalLabor2015.csv"))
However when I try to insert this code:
protected void ImportButton_Click(object sender, EventArgs e)
{
if (this.FileUpload.HasFile)
{
var extension = Path.GetExtension(FileUpload.FileName);
if (extension == ".csv")
{
using StreamReader reader = new StreamReader(FileUpload.FileContent))
}
}
}
It just imports the file and the rest of my code is not executed.

Here is my code:
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(NRFileUpload.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) as 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;
 
            }
 
        }
 
    }
}

AnswerRe: How do I access a csv file without hardcoding it in my code? Pin
Abhinav S29-Apr-15 17:04
Abhinav S29-Apr-15 17:04 
QuestionRe: How do I access a csv file without hardcoding it in my code? Pin
Norris Chappell30-Apr-15 4:56
Norris Chappell30-Apr-15 4:56 
AnswerRe: How do I access a csv file without hardcoding it in my code? Pin
Norris Chappell30-Apr-15 7:01
Norris Chappell30-Apr-15 7:01 
QuestionExport data to excel in asp.net Pin
Obaidullah Sulaimankhail26-Apr-15 20:07
Obaidullah Sulaimankhail26-Apr-15 20:07 
AnswerRe: Export data to excel in asp.net Pin
Abhinav S27-Apr-15 19:00
Abhinav S27-Apr-15 19:00 
QuestionServer Side Code and Client Side Code Pin
King Fisher23-Apr-15 18:37
professionalKing Fisher23-Apr-15 18:37 
AnswerRe: Server Side Code and Client Side Code Pin
aarif moh shaikh24-Apr-15 0:10
professionalaarif moh shaikh24-Apr-15 0:10 
AnswerRe: Server Side Code and Client Side Code Pin
Kornfeld Eliyahu Peter26-Apr-15 20:32
professionalKornfeld Eliyahu Peter26-Apr-15 20:32 
QuestionHow do I assign Session value to label in Asp.net? Pin
samflex23-Apr-15 4:52
samflex23-Apr-15 4:52 
AnswerRe: How do I assign Session value to label in Asp.net? Pin
F-ES Sitecore23-Apr-15 22:37
professionalF-ES Sitecore23-Apr-15 22:37 
QuestionUse of LastOrDefault() Pin
Member 1096876723-Apr-15 0:16
Member 1096876723-Apr-15 0:16 
AnswerRe: Use of LastOrDefault() Pin
Richard Deeming23-Apr-15 2:05
mveRichard Deeming23-Apr-15 2:05 
QuestionHow to encrypt message in WCF by writing code Pin
Tridip Bhattacharjee22-Apr-15 22:05
professionalTridip Bhattacharjee22-Apr-15 22:05 
AnswerRe: How to encrypt message in WCF by writing code Pin
Richard MacCutchan22-Apr-15 23:28
mveRichard MacCutchan22-Apr-15 23:28 
AnswerRe: How to encrypt message in WCF by writing code Pin
Gerry Schmitz24-Apr-15 16:08
mveGerry Schmitz24-Apr-15 16:08 
QuestionMultiple page redirection in ASP.NET WebApi Pin
Abdul Shakoor p22-Apr-15 20:34
Abdul Shakoor p22-Apr-15 20:34 
Questiondefault gridview listing not showing on page Pin
spirospap22-Apr-15 14:30
spirospap22-Apr-15 14:30 

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.