|
Quote: If that is the case why didn't I need to have it when I did the select on the "where not exists" query? Sorry, I'm tired - now I think I understood what you meant: The DataAdapter on this line: dataAdapter.Fill(dataTable); opens the connection automatically if it isn't already, but cmd.ExecuteNonQuery(); doesn't, so after un-commenting that line it became neccessary to open the connection explicitly.
Quote: One more thing My perm table is called TempTable maybe I should create the temp table with a different name? I think you're tired too Yes, you should have renamed or deleted the perm table. (I actually don't know if it would be a problem, I just told you to do that to avoid a potential error.)
Quote: Okay didn't get the error. However, I don't see the table in SQL Server? It's a temporary table. It exists only during the lifetime of the connection and is only visible to that connection.
Quote: I tried to query it and got an error? Always tell the exact error message when you're trying to get help
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sorry again. You are right I am tired too. I think I am good for now. I can figure out the hours issue. You have been so helpful and I have learn a lot from you. Thank you for being so patience with me. What time zone are you in? Are you from France?
|
|
|
|
|
You're welcome! But if you can't figure out the hours issue, feel free to ask.
I'm from Germany, one of my ancestors came from France
Good luck and good night!
cheers, Sascha
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I need to replace:
using (StreamReader reader = File.OpenText(@"c:\Users\pzd74f\Downloads\TestLabor2015.csv"))
with something like this:
protected void ImportButton_Click(object sender, EventArgs e)
{
if (this.FileUpload1.HasFile)
{
var extension = Path.GetExtension(FileUpload1.FileName);
if (extension == ".csv")
{
StreamReader csvreader = new StreamReader(FileUpload1.FileContent);
I need to have the user to be able to import the file instead of the csv be hardcoded.
|
|
|
|
|
Just pass FileUpload1.FileContent as an argument to QueryStaff
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
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)
{
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 = new StreamReader(NewResourceFileUpload.FileContent))
{
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) 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;
}
}
}
}
|
|
|
|
|
I'm sorry, I can't really help there, as I'm unfamiliar with ASP.NET. If I recall correctly, you took over this project from somebody else, right? I imagine there should be some code handling button-clicks in other parts of the application. Maybe you can take that as a kind of template how to do it. Else I would suggest you to open a new question in the ASP.NET forum so someone else can hopefully help you there.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Okay thanks. I going to submit what I have to my Director. They will just need to name the csv what I have in the code. I never got the hours to work.
|
|
|
|
|
Sascha,
The Director is happy with code but would like to see the hours.
I looped thru the code with debug and see that the #temptable is showing the hours
but are not summing then. Would this select statement be where I need to focus?
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;"; I have tried several different scenarios but no results.
Thanks,
Norris
|
|
|
|
|
Hi Norris,
there's no # in front of "TempTable" there. If it's the same in your code, that might be the problem. If it's not that I have no further ideas because it works for me. I hope you'll be able to fix it - good luck!
/Sascha
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Ok. Thank you for your help.
|
|
|
|
|
Okay got it figure out for the Hours. I needed to add to sum(Tmp.Hours) as Hours.
|
|
|
|
|
Cheers!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
io ho questo codice ma non mi riesce a mattere il dato di uscita nella stessa riga del dato di entrata. come faccio a inserire entrata e uscita nella stessa riga che contiene stesso nome sensa dupplicare.. grazie
https://social.msdn.microsoft.com/Forums/getfile/648856
https://social.msdn.microsoft.com/Forums/getfile/648857
OleDbConnection cn = DataBase.CreaConnessione();
OleDbDataAdapter ad = new OleDbDataAdapter();
Operai o = new Operai();
DateTime entrata;
DateTime uscita;
TimeSpan tmp;
private void Form2_Load(object sender, EventArgs e)
{
}
private void btnentrata_Click(object sender, EventArgs e)
{
entrata = DateTime.Now;
txtentrata.Text = entrata.ToLongTimeString();
OleDbCommand cmd = cn.CreateCommand();
cmd.CommandText = "INSERT INTO operai (cognome,nome,entrata) VALUES ('" + this.txtcognome.Text + "','" + this.txtnome.Text + "','" + this.txtentrata.Text + "')";
cmd.CommandType = CommandType.Text;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
private void btuscita_Click(object sender, EventArgs e)
{
uscita = DateTime.Now;
txtuscita.Text = uscita.ToLongTimeString();
OleDbCommand cmd = cn.CreateCommand();
cmd.CommandText = "INSERT INTO operai (cognome,nome,uscita) VALUES ('" + this.txtcognome.Text + "','" + this.txtnome.Text + "','" + this.txtuscita.Text + "')";
cmd.CommandType = CommandType.Text;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
|
|
|
|
|
I'm sorry but the main forums are English language only. Could you please translate your question?
|
|
|
|
|
INSERT the dates in the database access ( not Generating One new)
OleDbConnection cn = DataBase.CreaConnessione();
OleDbDataAdapter ad = new OleDbDataAdapter();
Operai o = new Operai();
private void Form2_Load(object sender, EventArgs e)
{
}
private void btnentrata_Click(object sender, EventArgs e)
{
txtentrata.Text = DateTime.Now.ToLongTimeString();
OleDbCommand cmd = cn.CreateCommand();
cmd.CommandText = "INSERT INTO operai (nome,cognome,entrata) VALUES ('" + this.txtnome.Text + "','" + this.txtcognome.Text + "','" + this.txtentrata.Text + "')";
cmd.CommandType = CommandType.Text;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
private void btuscita_Click(object sender, EventArgs e)
{
txtuscita.Text = DateTime.Now.ToLongTimeString();
OleDbCommand cmd = cn.CreateCommand();
cmd.CommandText = "INSERT INTO operai (nome,cognome,uscita) VALUES ('" + this.txtnome.Text + "','" + this.txtcognome.Text + "','" + this.txtuscita.Text + "')";
cmd.CommandType = CommandType.Text;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
|
|
|
|
|
Your code is vulnerable to SQL Injection[^].
NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
To update the same row, you will need to retrieve and store the ID from the new row, and then issue an UPDATE statement:
private int? _id;
private void btnentrata_Click(object sender, EventArgs e)
{
using (OleDbConnection cn = DataBase.CreaConnessione())
using (OleDbCommand cmd = cn.CreateCommand())
{
cmd.CommandText = "INSERT INTO operai (cognome, nome, entrata) VALUES (?, ?, ?)";
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("p0", txtcognome.Text);
cmd.Parameters.AddWithValue("p1", txtnome.Text);
cmd.Parameters.AddWithValue("p2", DateTime.Now);
cn.Open();
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT @@IDENTITY";
cmd.Parameters.Clear();
_id = (int)cmd.ExecuteScalar();
}
}
private void btuscita_Click(object sender, EventArgs e)
{
if (_id == null)
{
throw new InvalidOperationException("Row not created!");
}
using (OleDbConnection cn = DataBase.CreaConnessione())
using (OleDbCommand cmd = cn.CreateCommand())
{
cmd.CommandText = "UPDATE operai SET uscita = ? WHERE ID = ?";
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("p0", DateTime.Now);
cmd.Parameters.AddWithValue("p1", _id);
cn.Open();
cmd.ExecuteNonQuery();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm doing SMS system.Unable to load DLL "dllforvc.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E).
|
|
|
|
|
That's telling you that it cannot find either dllforvc.dll or another DLL in its dependency chain. In cases like this, I would look to use this[^] to help find what's missing.
|
|
|
|
|
I think dllforv.dll is worry. Do you have available dllforvc.dll?
|
|
|
|
|
|
I ask you to help me transfer code below into C#2008 to C#2005 ?, which takes the form type class DataClass.cs
[CODE]
// Example 1:
private void PopulateArr(DataClass[] tmpArr)
{
for (int i = 0; i < 3; i++)
{
tmpArr[i] = new DataClass() { DoubleValue = seed++ }; //error this place
}
}
//Example 2:
/// public static implicit operator DataClass(double? othaNumba)
/// public static implicit operator DataClass(double othaNumba)
/// can you explain why the declaration on (Example 2a and 2b) parameters included in the question mark and no question mark ?
// Example 2a:
public static implicit operator DataClass(double? othaNumba)
{
return new DataClass() //error this place
{
DoubleValue = othaNumba == null ? null : (double?)Convert.ToDouble(othaNumba) // error this place
};
}
// Example 2b:
public static implicit operator DataClass(double othaNumba)
{
return new DataClass() // error this place
{
DoubleValue = othaNumba == null ? null : (double?)Convert.ToDouble(othaNumba) // error this place
};
}
// Example 3:
private void filterControl1_BeforeShowValueEditor(object sender, ShowValueEditorEventArgs e) // error this place
{
GridFilterColumn currentColumn = e.CurrentNode.Property as GridFilterColumn;
if (currentColumn != null)
{
e.CustomRepositoryItem = currentColumn.GridColumn.ColumnEdit;
}
}
// Error 13 The type or namespace name 'ShowValueEditorEventArgs' could not be found
// (are you missing a using directive or an assembly reference?)
[/CODE]
|
|
|
|
|
Normal Value Type variables cannot contain null values - but C# allows you to create a version that can called a Nullable Type[^] by appending a "?" to the type name when you declare the value - the link explains all this.
The rest of the code you show is pretty much rubbish: it amounts to
If the value is null , return null .
Otherwise, convert the double value to a double , then cast it to a nullable double .
Why?
The original value is a double , which can't be null (because it's a Value Type) so just cast it to a nullable double anyway...
And your other example is equally ridiculous.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Examples 1 and 2 are using object initializers[^], which were introduced with VS2008. To compile the code in VS2005, you'll need to use the older initialization syntax. For example:
tmpArr[i] = new DataClass { DoubleValue = seed++ };
DataClass temp = new DataClass();
temp.DoubleValue = seed++;
tmpArr[i] = temp;
Example 3 appears to be related to a DevExpress component. Either you're missing a reference to the component, or you're missing a using directive for the namespace, or you're using a different version of the component in your VS2005 code.
Is there a reason you're using VS2005, when VS2013 Community Edition[^] is available free of charge?
And for future reference, when you're posting a code block, this site doesn't use [CODE]...[/CODE] tags. Use either <pre> tags or fenced code blocks to format your code:
<pre>
Your code here
</pre>
Or:
```
Your code here
```
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The first of all thank you for answering me, now I want to convert the code example 2 (2a and 2b included) to C# 2005 I will write again how ?
|
|
|
|