|
We would love to help but without the error we can only guess which of the 1,234,744 possible errors it is.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
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)
{
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))
{
conn.Open();
cmd.CommandText = "CREATE TABLE #TempTable(Name nvarchar(100) NOT NULL, Hours decimal(6, 2) NOT NULL);";
cmd.ExecuteNonQuery();
DataTable dataTable = new DataTable();
cmd.CommandText = "SELECT * FROM #TempTable;";
dataAdapter.Fill(dataTable);
dataTable.BeginLoadData();
using (StreamReader reader = File.OpenText(@"c:\Users\pzd74f\Downloads\FinalLabor2015.csv"))
{
string line;
if (reader.ReadLine() != null)
{
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();
dataAdapter.Update(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;
}
}
}
}
|
|
|
|
|
|
Hi,
Thanks for the information. I was able to get the correct code but where do I put this in my code?
protected void UploadButton_Click(object sender, EventArgs e)
{
if (NRFileUploadControl.HasFile)
{
try
{
string filename = Path.GetFileName(NRFileUploadControl.FileName);
NRFileUploadControl.SaveAs(Server.MapPath("~/") + filename);
StatusLabel.Text = "Upload status: File uploaded!";
}
catch (Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
It just runs this part and don't execute the rest of my code.
Thanks,
Norris
|
|
|
|
|
Abhinav,
I want to thank you for provided those websites.
If you have the time could you look at my code and let me know where I need to insert the new code?
|
|
|
|
|
How to export data to excel page step by step that shows headerrow, headersubrow, data row and total row asp.net?
|
|
|
|
|
|
|
I you have any Security level project/task than always use Server Side code... but if no need to security than always use Client side because it's more faster than Server side...
|
|
|
|
|
It is a classic question for the answer - it depends...
Of course it has nothing to do with security - the data always coming from the server and always displayed on the client, so you have no problem to check security before it got displayed...
What you actually have to see is the requirements of your system, see what the units of the data and how those units are related to actions made in the system...For instance: is your data for display only, or you are going to edit it. Are you going to display a single page of data (small amount) or we are talking about a huge amount of it (paging)...
So it is not a question to answer as there is no one-size-for-all answer, but you have to analyze and design the system at hand...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
I have this link control that passes values via querystring to another page:
ItemTemplate>
<asp:HyperLink ID="hdReserve" class="js_siteid" AutoPostBack="false" runat="server" Text="Select"
Navigateurl='<%# String.Format("requestSummary.aspx?id={0}&groupsize={1}&facilityFees={2}&depoitAmt={3}&cancelAmt={4}&keydeptAmt={5}&extrahour={6}&facility={7}&hoursdiff={8}", CType(Container.DataItem, System.Data.DataRowView)("siteId") , ddlPartySize.SelectedValue,CType(Container.DataItem, System.Data.DataRowView)("RentalFeeAmount"),CType(Container.DataItem, System.Data.DataRowView)("DepositAmount"),CType(Container.DataItem, System.Data.DataRowView)("CancellationAmount"),CType(Container.DataItem, System.Data.DataRowView)("DepositAmount"),CType(Container.DataItem, System.Data.DataRowView)("ExtraHourAmount"),CType(Container.DataItem, System.Data.DataRowView)("AssetName"), hf1.Value) %>' />
</ItemTemplate>
A user clicks the link but before the user is redirected to requestSummary.aspx page, user is prompted to login.
After a successful login, the user is then taken to that page.
The issue I am running into is that the querystring values that are passed to requestSummary.aspx are now empty.
To resolve this, I attempted to assign these values to session and passed the values back to the label controls.
This is not working as the controls are still blank.
This is what I have tried, just one example to show what I have tried:
'retrieve querystring values for hoursdiff:
'the markup - label control:
<td style="font-weight:bold"> Extra Hours: <asp:Label ID="lblhourspassedval" runat="server" /></td>
Dim intHours As Integer = 0
intHours = Request.QueryString("hoursdiff")
'Assign intHours to session:
Session("intHours")
Pass the session value back to the label control:
lblhourspassedval.Text = Session("intHours")
So far, the label control is still blank.
What am I doing wrong?
I have been struggling with this for a whole day.
Thanks a lot in advance.
|
|
|
|
|
This
Session("intHours")
needs to be
Session("intHours") = intHours
You might also need to amend where you are setting the text value
if (Session("intHours) Is Not Nothing) then
lblhourspassedval.Text = Session("intHours").ToString
end if
I don't know vb.net, the above is just a guess but I'm sure you can work it out.
The other issue you might be having is if you are always setting the session variable from the querystring and you visit the page when there is nothing in the querystring then your session variables will be cleared. You can check if the value you're looking for exists on the querystring using something like
if not string.IsNullOrWhiteSpace(Request.QueryString("yourvar")) then
|
|
|
|
|
I need to extract the last data so i used the following code in MVC controller:
var cmpid = db.complaint_master.Where(m => m.uid == id && m.isvalid == 0 && m.dateofcomplaint == date).Select(m => m.compid).LastOrDefault();
i am getting an error:
LINQ to Entities does not recognize the method 'Int32 LastOrDefault[Int32](System.Linq.IQueryable`1[System.Int32])' method, and this method cannot be translated into a store expression.
Please help
|
|
|
|
|
You have two options:
1. Sort the data in descending order, and use FirstOrDefault :
var cmpid = db.complaint_master
.Where(m => m.uid == id && m.isvalid == 0 && m.dateofcomplaint == date)
.Select(m => m.compid)
.OrderByDescending(id => id)
.FirstOrDefault()
;
2. Load all of the results into memory before using LastOrDefault :
var cmpid = db.complaint_master
.Where(m => m.uid == id && m.isvalid == 0 && m.dateofcomplaint == date)
.Select(m => m.compid)
.AsEnumerable()
.LastOrDefault()
;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i want to develop a wcf service which will send encrypted message / response to client and client will decrypt it and same way client will send data in encrypted format which wcf service decrypt it before taking any action.
i hard that wcf has message inspector which can do it but not getting any easy understanding sample code to achieve the same. so please give me a sample code how to achieve it. also give me sample code for both wcf service and client side code.
please do not tell me to use certificate rather guide me what kind of code i need to write at service end and client to encrypt/decrypt data. please discuss here or redirect me to relevant article. thanks
tbhattacharjee
|
|
|
|
|
Tridip Bhattacharjee wrote: give me a sample code how to achieve it. also give me sample code for both wcf service and client side code. You have been a CodeProject member long enough to know that this site does not provide code to order.
|
|
|
|
|
Gimme gimme never gets,
don't you know your manners yet?
|
|
|
|
|
I am trying to develop a appliction in asp.net webapi and knockoutjs VM, Please help me how to create new page and how to redirect to a new page from home page or masterpage.
|
|
|
|
|
I have the following:
<asp:linkbutton id="LinkButton1" runat="server" onclick="LinkButton1_Click">Find Project :
<asp:textbox id="FindProject" runat="server" text="" cssclass="submit">
<asp:SqlDataSource ID="MySqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="SELECT * from myTable
WHERE Active= 'True'
AND myTable.Project = COALESCE(NULLIF(@FindProject, ''), myTable.Project)">
<SelectParameters>
<asp:ControlParameter ControlID="FindProject" Name="FindProject"
PropertyName="Text" />
</SelectParameters>
<asp:gridview id="GridView1" runat="server" datasourceid="MySqlDataSource1" ...="">
...
The SQL is simple and works ok with all of the values below in SSMS:
--declare @FindProject varchar(20) = 'A_Project'
--declare @FindProject varchar(20) = NULL
declare @FindProject varchar(20) = ''
select * from MyTable
WHERE Active = 'True'
AND MyTable.Project = COALESCE(NULLIF(@FindProject, ''), MyTable.Project )
Currently I can find an individual record with the linkbutton and FindProject textbox, it works ok
I want the page to show all records when the page is initially loaded, which it doesn't, it's just an empty list.
|
|
|
|
|
Try setting CancelSelectOnNullParameter[^] to false :
<asp:SqlDataSource ID="MySqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="SELECT * from myTable WHERE Active= 'True' AND myTable.Project = COALESCE(NULLIF(@FindProject, ''), myTable.Project)"
CancelSelectOnNullParameter="False"
>
<SelectParameters>
<asp:ControlParameter
ControlID="FindProject"
Name="FindProject"
PropertyName="Text"
/>
</SelectParameters>
</asp:SqlDataSource>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
excellent thanks, it worked.
|
|
|
|
|
please help
Im using MySql database and asp.net c#
I have a listview like this
<asp:listview id="listview1" runat="server">
<item template="">
"
"
"
<%# val("pic ") %>
and its working now im struggling with paging .
i tried a datapager n i failed please help ...
which tool to use if i want to click a picture
from the listview and see full products details.
Thanks
|
|
|
|
|
Hi All,
I am getting the following error when I try to run my ASP.Net web-forms application with my database credentials but I run the same application with my other colleagues database credentials I am not getting the error, then I thought may be my Db credentials are messed up then I tried to see if any difference exists in my authentication/authorization credentials, but I didn't find any difference between his credentials and my credentials. I am not understanding what could be the error and where am I missing, I am searching and trying to find the reason, but in this meantime if you know the solution please help me.
Here is my error on the VS crashing
[Window Title]
Visual Studio Just-In-Time Debugger
[Main Instruction]
An unhandled Microsoft .NET Framework exception occurred in w3wp.exe [3596].
The Just-In-Time debugger was launched without necessary security permissions. To debug this process, the Just-In-Time debugger must be run as an Administrator. Would you like to debug this process?
[V] View process details [Yes, debug w3wp.exe] [No, cancel debugging]
[Expanded Information]
Process Name: w3wp.exe
User Name: IIS APPPOOL\ELMS [Elevated]
And when I try to see it in the Windows log here it is
Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2
Faulting module name: clr.dll, version: 4.0.30319.18444, time stamp: 0x52717f9a
Exception code: 0xc00000fd
Fault offset: 0x0000000000009f66
Faulting process id: 0x141c
Faulting application start time: 0x01d07b8b53af8a8c
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Report Id: a1f85976-e77e-11e4-8858-08002703e456
Please help me if this can be because of my settings in the IIS or SQL Server or Windows credentials in this meantime I am searching in the code for any possible problems. Thanks in advance.
"There is enough hatred in the world, lets spread love compassion and affection."
|
|
|
|
|
Thanks I got it resolved, I had some problems in my database auth tables hence a function getting called repeatedly and killing the Worker process. I have resolved it.
"There is enough hatred in the world, lets spread love compassion and affection."
|
|
|
|
|
hello :
how can i please build graph has two part ( bi-part) , have like node friends facebook and posts facebook , link between two nodes( node friend and node post ) may be : like , comment and share ??
and how please can use library JoinJS to do it
thank you very much
|
|
|
|