|
hi,
I have written the following code to export data from Excel
string tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "Report.csv");
GView.SelectAllCells();
GView.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
ApplicationCommands.Copy.Execute(null, GView);
String result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
GView.UnselectAllCells();
System.IO.StreamWriter file1 = new System.IO.StreamWriter(tempPath);
file1.WriteLine(result);
file1.Close();
Excel.Application app = new Excel.Application();
Excel.Workbook workbook = app.Workbooks.Open(tempPath);
Excel.Worksheet ws = workbook.Worksheets[1];
I have 2 columns contain dates. both of them looks dd/MM/yyyy on the data grid which is correct.
once out on excel they change to american date format!?
the weired thing is, before the 13th of every month they are in american format. after the 13th they show UK format.
can some guru help me please
|
|
|
|
|
You need to format the cells in Excel.
|
|
|
|
|
I'm currently in a trade-school type program to become a .NET developer, and am in a 'project management' mini course that has a project that requires me and my teammates to gather 30 interviews with .NET developers. To simplify this, we have created a simple survey that asks the questions we need answered.
It would help us out a lot if you could give us some feedback! I promise this isn't spam! Here is a link to the survey (via Google Forms).
https://docs.google.com/forms/d/1A6c8YrD0zUZ-EEBeW4Coybum8dgwAXkFW-bZvg714Qc/viewform[^]
|
|
|
|
|
This has nothing to do with C#, and should be posted in the Lounge, not the programming forums.
|
|
|
|
|
Sorry about that, I didn't know where to post this and was unaware of the Lounge section under the community tab. I tried to delete this thread, but am unable to do so. Anyways, sorry for the error!
|
|
|
|
|
Hi there,
how can I change the text of my textbox, while the code is running?
I will change it when I click on the button "search", and while the programm is searching the text in my textbox should be "searching ..."
Can anyone help me please?
|
|
|
|
|
Um...
myTextBox.Text = "Searching...";
I'm sure that isn't the problem you are having, but I can't work out from that little what problem you want us to solve.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I think you are asking how you can use the TextBox as both the source of what to search for and, then, while searching, a kind of progress indicator.
If this is what you want, I'd argue against that because:
1. if the computer this runs on is not very powerful, you may delay the search.
2. if the computer this runs on is super-powerful, all you may see is a meaningless blur.
3. there is a traditional way of doing this: use either a progress-bar or a status-bar control.
There are good resources here on CP for using both progress-bar and/or status-bar with a process (like search) running in its own thread, which is desirable so that the main UI does not become frozen, and the user may have the opportunity to cancel the search, etc.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Okay but how can I show that it is searching?
|
|
|
|
|
Is there a way to change the speech recognition language, without installing language packs in windows or by installing them, but not changing the default language pack?
|
|
|
|
|
|
Upvoted; might not have been what he wants to hear, but it is correct.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Have areal 5 back, for telling the truth.
|
|
|
|
|
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1;
What's wrong with this bracket
private void BindGrid()
{
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand("SELECT Rasm FROM rasmlar where Rasm_ID IN (" + String.Join(",", getRasm_ID1()) + ")", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
gvImages.DataSource = dt;
gvImages.DataBind();
}
|
|
|
|
|
That depends entirely on what's returned by getRasm_ID1() and what the column type of Rasm_ID .
If you're going to build a string to hold the SQL statement, put the statement into a string variable so you can examine the contents of the string in the debugger before you create a MySqlCommand object with it.
|
|
|
|
|
After creating the command, examine what the statement in cmd.CommandText looks like to see the problem. Few possibilities that come in mind:
|
|
|
|
|
Your code is vulnerable to SQL Injection[^].
NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
private void BindGrid()
{
using (MySqlConnection con = new MySqlConnection(constr))
using (MySqlCommand cmd = new MySqlCommand(string.Empty, con))
{
var sb = new System.Text.StringBuilder("SELECT Rasm FROM rasmlar where Rasm_ID IN (");
foreach (var id in getRasm_ID1())
{
if (cmd.Parameters.Count != 0)
{
sb.Append(',');
}
string name = "@p" + index;
cmd.Parameters.AddWithValue(name, id);
sb.Append(name);
}
sb.Append(')');
cmd.CommandText = sb.ToString();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
gvImages.DataSource = dt;
gvImages.DataBind();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am trying to solve the following problem but my code is not so good. Could anybody help me a little bit.
Write a function that provides change directory (cd) function for an abstract file system.
Notes:
Root path is '/'.
Path separator is '/'.
Parent directory is addressable as "..".
Directory names consist only of English alphabet letters (A-Z and a-z).
For example, new Path("/a/b/c/d").Cd("../x").CurrentPath should return "/a/b/c/x".
Heres my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
public class Path
{
public string CurrentPath { get; private set; }
public Path(string path)
{
this.CurrentPath = path;
}
public Path Cd(string newPath)
{
Path pathStr = new Path(this.CurrentPath);
if (newPath == null | newPath == string.Empty)
{
throw new System.NotSupportedException("Waiting to be implemented.");
}
string patternUp = "([\\.]{2}/)+[a-zA-z]+";
string patternDown = @"/([a-zA-z]*)";
var matchesUp = Regex.Matches(newPath, patternUp);
var matchesDown = Regex.Matches(newPath, patternDown);
if (matchesUp.Count > 0)
{
var countUp = newPath.Count(c => c == '.');
pathStr.CurrentPath = pathStr.CurrentPath.Substring(0, pathStr.CurrentPath.Length - countUp);
pathStr.CurrentPath = pathStr.CurrentPath + "/" + newPath.Replace("../", "");
}
else
{
pathStr.CurrentPath = pathStr.CurrentPath + newPath.Replace("../", "");
}
return new Path(pathStr.CurrentPath);
}
public static void Main(string[] args)
{
Path path = new Path("/a/b/c/d");
Console.WriteLine(path.Cd("../x").CurrentPath);
}
}
|
|
|
|
|
Sure. You don't need the RegEx's at all. All you need is to split the passed in string on the "/" characters and process the items found from left to right.
This sniffs of a homework assignment.
|
|
|
|
|
What happens using the code example you give now ? Errors ? If so, what ?
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Hello there,
Please have a look in this code:
ERROR LINE IS JUST BELOW #REGION YEARLYTAX... (COMMENTED)
private void ImportData_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
#region Delete Previous Data...
if (MessageBox.Show("Delete all previous records?", "DELETE ALL", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
{
if (MessageBox.Show("ALL RECORDS WILL BE DELETED PERMANENTLY... ARE YOU SURE?", "DELETE ALL", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
{
lblMessage.Content = "Please wait...";
Cursor = Cursors.Wait;
Engine E = new Engine();
SQLiteCommand CMD = new SQLiteCommand("DELETE FROM YEARS", E.Conn);
CMD.ExecuteNonQuery();
CMD = new SQLiteCommand("DELETE FROM WARDS", E.Conn);
CMD.ExecuteNonQuery();
CMD = new SQLiteCommand("DELETE FROM USERS", E.Conn);
CMD.ExecuteNonQuery();
CMD = new SQLiteCommand("DELETE FROM SETTINGS", E.Conn);
CMD.ExecuteNonQuery();
E.Dispose();
CMD.Dispose();
Cursor = null;
}
else goto Import;
}
#endregion
Import:
ButtonsPanel.IsEnabled = false;
FrmClose.IsEnabled = false;
BW.WorkerSupportsCancellation = false;
BW.WorkerReportsProgress = true;
BW.WorkerSupportsCancellation = false;
BW.DoWork += BW_DoWork;
BW.ProgressChanged += BW_ProgressChanged;
BW.RunWorkerCompleted += BW_RunWorkerCompleted;
BW.RunWorkerAsync();
lblMessage.Content = "Done...";
ButtonsPanel.IsEnabled = true;
FrmClose.IsEnabled = true;
}
void BW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
lblMessage.Content = "Done...";
Progress.Value = 0;
}
void BW_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Progress.Value = e.ProgressPercentage;
}
void BW_DoWork(object sender, DoWorkEventArgs e)
{
Progress.Value = 0;
#region YearlyTax...
var INF = new IniFile(Path.Combine(Directories.OLD_DATAFOLDER, @"yt.txn"));
string[] T = INF.GetSectionNames();
Progress.Maximum = T.Length;
foreach (string M in T)
{
SQLiteCommand CMD = new SQLiteCommand(E.InsertSQL("YEARS"), E.Conn);
CMD.Parameters.AddWithValue("ID", Guid.NewGuid().ToString());
CMD.Parameters.AddWithValue("YEAR", M);
CMD.Parameters.AddWithValue("B6000", INF.GetDouble(M, "txt6000"));
CMD.Parameters.AddWithValue("I12000", INF.GetDouble(M, "txt12000"));
CMD.Parameters.AddWithValue("I100000", INF.GetDouble(M, "txt100000"));
CMD.Parameters.AddWithValue("I150000", INF.GetDouble(M, "txt150000"));
CMD.Parameters.AddWithValue("I200000", INF.GetDouble(M, "txt200000"));
CMD.Parameters.AddWithValue("I250000", INF.GetDouble(M, "txt250000"));
CMD.Parameters.AddWithValue("A250000", INF.GetDouble(M, "txtabove250000"));
CMD.Parameters.AddWithValue("SAMEKIT", INF.GetDouble(M, "samekit"));
CMD.Parameters.AddWithValue("VIVRANI", INF.GetDouble(M, "vivraniprapatrashulk"));
CMD.Parameters.AddWithValue("LATEFEESPERCENT", INF.GetDouble(M, "latefees"));
CMD.Parameters.AddWithValue("HOUSINGDISCOUNTPERCENT", INF.GetDouble(M, "housingdiscount"));
CMD.Parameters.AddWithValue("OWNERDISCOUNTPERCENT", INF.GetDouble(M, "completeownerdiscountpercent"));
CMD.Parameters.AddWithValue("WIDOWDISCOUNT", INF.GetDouble(M, "concessiontypediscount"));
CMD.ExecuteNonQuery();
lblMessage.Content = "Importing: " + M;
BW.ReportProgress(P++);
Thread.Sleep(30);
}
#endregion
BW.ReportProgress(0);
#region Wards...
T = Directory.GetFiles(Path.Combine(Directories.OLD_DATAFOLDER, "Wards"), "*.wrd", SearchOption.AllDirectories);
foreach (string M in T)
{
INF = new IniFile(M);
string[] Q = INF.GetSectionNames();
foreach (string L in Q)
{
SQLiteCommand CMD = new SQLiteCommand(E.InsertSQL("WARDS"), E.Conn);
CMD.Parameters.AddWithValue("ID", Guid.NewGuid().ToString());
CMD.Parameters.AddWithValue("WARDNUMBER", Convert.ToInt32(L));
CMD.Parameters.AddWithValue("ZONE", INF.GetInt32(L, "zone"));
CMD.Parameters.AddWithValue("NAME", INF.GetString(L, "name"));
CMD.Parameters.AddWithValue("MANAGER", string.Empty);
CMD.Parameters.AddWithValue("N1", INF.GetDouble(L, "m1"));
CMD.Parameters.AddWithValue("N2", INF.GetDouble(L, "m2"));
CMD.Parameters.AddWithValue("N3", INF.GetDouble(L, "m3"));
CMD.Parameters.AddWithValue("ON1", INF.GetDouble(L, "mn1"));
CMD.Parameters.AddWithValue("ON2", INF.GetDouble(L, "mn2"));
CMD.Parameters.AddWithValue("ON3", INF.GetDouble(L, "mn3"));
CMD.Parameters.AddWithValue("IN1", INF.GetDouble(L, "vm1"));
CMD.Parameters.AddWithValue("IN2", INF.GetDouble(L, "vm2"));
CMD.Parameters.AddWithValue("IN3", INF.GetDouble(L, "vm3"));
CMD.Parameters.AddWithValue("OIN1", INF.GetDouble(L, "vmn1"));
CMD.Parameters.AddWithValue("OIN2", INF.GetDouble(L, "vmn2"));
CMD.Parameters.AddWithValue("OIN3", INF.GetDouble(L, "vmn3"));
CMD.ExecuteNonQuery();
lblMessage.Content = "Importing: " + M;
BW.ReportProgress(P++);
Thread.Sleep(30);
}
}
#endregion
BW.ReportProgress(0);
#region Customers...
T = Directory.GetFiles(Path.Combine(Directories.OLD_DATAFOLDER, "Customer"), "custdata.cst", SearchOption.AllDirectories);
P = 0;
foreach (string M in T)
{
INF = new IniFile(M);
SQLiteCommand CMD = new SQLiteCommand(E.InsertSQL("Customers"), E.Conn);
CMD.Parameters.AddWithValue("ID", Guid.NewGuid().ToString());
CMD.Parameters.AddWithValue("DEMAND", CheckDemand(INF.GetString("data", "voterid")));
CMD.Parameters.AddWithValue("AADHAR", INF.GetString("data", "aadhar").Trim());
CMD.Parameters.AddWithValue("WARDNUMBER", INF.GetInt32("data", "wno"));
CMD.Parameters.AddWithValue("NAME", INF.GetString("data", "name").Trim());
CMD.Parameters.AddWithValue("CASTE", INF.GetString("data", "caste").Trim());
CMD.Parameters.AddWithValue("ADDRESS1", INF.GetString("data", "address1").Trim());
CMD.Parameters.AddWithValue("ADDRESS2", INF.GetString("data", "address2").Trim());
CMD.Parameters.AddWithValue("PLOTNUMBER", INF.GetString("data", "plotno").Trim());
CMD.Parameters.AddWithValue("MOBILENUMBER", INF.GetString("data", "mobile").Trim());
CMD.Parameters.AddWithValue("LEDGERBALANCE", 0);
CMD.ExecuteNonQuery();
lblMessage.Content = "Importing: " + Path.GetFileName(M);
BW.ReportProgress(P++);
Thread.Sleep(30);
}
#endregion
}
Any help is appreciated.
Thanks in advance.
|
|
|
|
|
That doesn't make a lot of sense:
var INF = new IniFile(Path.Combine(Directories.OLD_DATAFOLDER, @"yt.txn"));
If it's a static class, you can't create a variable or an instance of it!
So either you will get a couple of error messages telling you that, and your app won;t compile; or it isn't a static class at all, and the problem is in the class constructor.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello Friend,
sorry for my long code and IniFile is not static. moreover, IniFile is not static.
Here is the exception report:
System.InvalidOperationException was unhandled by user code.
Additional information: The calling thread cannot access this object because a different thread owns it.
And the line where I am getting the code:
var INF = new IniFile(Path.Combine(Directories.OLD_DATAFOLDER, @"yt.txn"));
|
|
|
|
|
So look at the line, and there are two possible parts:
Directories.OLD_DATAFOLDER Which looks like an enum , but we can't see it. If it's an enum then its won't be that.
new IniFile(...); Which means it's in the constructor, which we can't see.
You've got a cross threading error in code we can't see which probably shouldn't be using threads and the fragment you show use doesn't use threading anyway.
That doesn't exactly make it easy for us to work out what your problem might be...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It would be much more helpful if you put only the relevant parts of the code, and showed the exact text of the error message.
|
|
|
|
|