|
Yeh, a windows service is what ti wil become but I wanted to get a hang of threading and memory management before I ran chasing after service bugs!
I looked at the service template (provided on this site) which looks great but a background worker thread which I understand I would use I think eneds more or less demands the same kind of approach to the above code, so I'm predicting I'd still end up with a memory issue, what do you think?
|
|
|
|
|
c4tchm4tt wrote: I'd still end up with a memory issue
You might, but neither technique seems more prone.
c4tchm4tt wrote: a background worker thread
Some people use those, but I choose to use a System.Timers.Timer for my Windows Services.
|
|
|
|
|
how can make master page in C# window application form...?
|
|
|
|
|
Check this [^]
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
What do you think a "master page" is ?
best, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
|
|
|
|
|
Do you mean a MDI container?
|
|
|
|
|
There is no concept of master pages in Windows Forms.
Searching on the internet may provide you with some workarounds.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
May be a "inherited form" will help you(I guess so)
|
|
|
|
|
i try to connect to dbf database using C# (i try 3 types of connection)
string connectionString = @"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\employees.dbf;";
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\employees.dbf;Extended Properties=dBASE IV;";
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\employees.dbf;Extended Properties=dBASE IV;User ID=Admin;Password=;";
using (OdbcConnection connection = new OdbcConnection(connectionString))
{
connection.Open();
}
and i got error
error1:
ERROR [HY024] [Microsoft][ODBC dBase Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
ERROR [HY024] [Microsoft][ODBC dBase Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
or error2:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
what can be the problem ?
thanks in advance
|
|
|
|
|
goldsoft wrote: '(unknown)' is not a valid path.
goldsoft wrote: Data source name not found
Both errors seem to be saying the same thing. The file does not exist where you say it should be.
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
Hi,
Maybe try to escape backslashes in your connection string (i.e., write \\ instead of \ ).
|
|
|
|
|
No need to try; it's a verbatim[^] string; C# doens't interprete them as escape-sequences when prefixed with the @-sign.
Bastard Programmer from Hell
|
|
|
|
|
The two last ones are OleDB drivers, not ODBC drivers. If it is giving you an ODBC driver error it means that it is expecting an ODBC. Since it seems to be a DBase IV database I doubt there even is an OleDb driver for it.
Did you check this[^] site? it might help.
Also make sure the dbf file is actually in the C drive. looks like a weird place to put it IMHO.
Hope this helps.
V.
|
|
|
|
|
|
Hi everybody,
on the portal http://www.blackbeltfactory.com (previusly targetting java) we try to develop community for C# and SQL Server training.
I do hope some of you will also find it useful to support this idea with their knowledge.
Regards
Gsue44
(please forgive if you take it as spam. that was not my intention)
|
|
|
|
|
Hi all,
I am trying to implement read and write functionality between DataGridViewload controls and an XML file.
The code to write the the XML file is as follows
DataTable dt_csk = new DataTable("CONTROL_KEYS");
dt_csk.Columns.Add("key", typeof(System.String));
dt_csk.Columns.Add("value", typeof(System.String));
for (idx = 0; idx < dgv_csk.Rows.Count; idx++)
{
dt_csk.Rows.Add(dgv_csk[0, idx].Value.ToString(), dgv_csk[1, idx].Value.ToString());
}
dt_csk.EndLoadData();
dt_csk.AcceptChanges();
dgv_csk.DataSource = dt_csk.DefaultView;
I then add all DataTables to a DataSet like so
DataSet ds = new DataSet();
ds.Tables.Add(dt_csk);
ds.Tables.Add(dt_cdk);
ds.Tables.Add(dt_cak);
ds.WriteXml(logfile, XmlWriteMode.IgnoreSchema);
I read the XML into the DataGridView elements as follows:
XmlDataDocument xmldata = new XmlDataDocument();
xmldata.DataSet.ReadXml(xml_filename);
dgv_csk.DataSource = xmldata.DataSet;
dgv_csk.DataMember = "CONTROL_STATIC_KEYS";
This works great but there is one problem.
PROBLEM When I import info from the XML file, there is one additional row that is blank in each DataGridView control. I have some other functions where I use the number of rows in the DGV as an index, and this additional row is screwing things up.
Could you tell me what I am doing wrong?
Thanks!
N.
modified on Monday, August 29, 2011 1:57 AM
|
|
|
|
|
If user click dates
such as 2008-06-12 ~ 2011-09-25
I want to get year, month different not days.
example) 3years 2month
I am using TimeSpan function.
but this function only show day's difference.
hi
My english is a little.
anyway, nice to meet you~~
and give me your advice anytime~
|
|
|
|
|
How long is a year?
As you found, TimeSpan won't/can't do that, but you can probably do it manually.
|
|
|
|
|
It depends on what you really want. For example 3 Years and 2 months could be between 1154 and 1158 days depending on which months you're actually talking about and if a leap year was included.
But I think for what you want you're going to have to just check the difference between the years/months/days yourself, I reckon something like this:
public struct Diff
{
public int Years;
public int Months;
public int Days;
};
public Diff Difference(DateTime start, DateTime end)
{
Diff diff = new Diff();
if (end.Day < start.Day)
{
end = end.AddMonths(-1);
int remainDays = DateTime.DaysInMonth(start.Year, start.Month) - start.Day;
diff.Days = remainDays + end.Day;
}
else
diff.Days = end.Day - start.Day;
if (end.Month < start.Month)
{
end = end.AddYears(-1);
diff.Months = 12 - (start.Month - end.Month);
}
else
diff.Months = end.Month - start.Month;
diff.Years = end.Year - start.Year;
return diff;
}
Which puts your example at 3 years and 3 months (and 13 days) since your further into September than you are into June, if you used 2008-06-12 ~ 2011-09-8 it would give 3 years 2 months 26 days. Which may or may not be quite what you want, but I think you get the idea.
Edit: Fixed function, mustn't write code when sleepy
|
|
|
|
|
Hello.
I am learning c# and reading my book "Head first c#"
In the interum, I would like to ask about generating random numbers.
My example uses the game "Roulette" where the wheel spins, and a number between 0 and 36 comes out.
I would like to ask the following questions:
1)What is the best (as in most random) way of generating a number between 0 and 36?
3)How would this be done if we had an animated roulette wheel, I ask this because if you play the game online, the ball may look as though it is ready to land on, say, 6, but then it appears to "bounce" to an adjacent number, is this down to a "random " value.
And lastly, lets say we are creating a random horse race, but the horse in question has a 80% chance of winning, how would we add this "odds" into a random value?
Thank you,
Stephen
|
|
|
|
|
Have a look at the Random[^] class.
|
|
|
|
|
stephen.darling wrote: )What is the best (as in most random) way of generating a number between 0 and
36?
With a roulette wheel.
As to the horse, he may be favored to win, but he doesn't have an "80% chance of winning". However, one of the techniques I like to use to select a random entity, from amomg various entities with varying chances of being selected, is to simulate putting slips into a hat, each entity may have a different number of slips in the hat, in proportion to their desired probability to be drawn.
|
|
|
|
|
PIEBALDconsult wrote: With a roulette wheel.
Are you suggesting there is no real way of randomising this?
PIEBALDconsult wrote: As to the horse, he may be favored to win, but he doesn't have an "80% chance of winning". However, one of the techniques I like to use to select a random entity, from amomg various entities with varying chances of being selected, is to simulate putting slips into a hat, each entity may have a different number of slips in the hat, in proportion to their desired probability to be drawn.
Please could you explain this a little further?
Thank you,
Steve
|
|
|
|
|
stephen.darling wrote: Please could you explain this a little further?
Given the concept of drawing a winner from a hat... in many situations, each entrant has one entry in the hat, and therefore an equal chance of being drawn (winning)... but, in some situations entrants have unequal probability of being drawn... this can be accomplished by the entrants having varying numbers of entries in the hat... when an entry is drawn, the more entries an entrant has, the greater the probability of being drawn. If you need to continue drawing other entrants, you can remove all the entries for the drawn entrant before continuing.
How this applies to horse racing, I don't know.
|
|
|
|
|
1) for random numbers
static Random _r = new Random();
static int F()
{
int n = _r.Next(0,36);
return n;
}
1a) - if you want to make bingo card
static void Main()
{
int[] numbers = new int[6];
for (int i = 0; i < numbers.Length; i++)
{
int a = F();
bool has = numbers.Contains(a);
if (has == true) {i--; }
else {
numbers[i]=a;
}
}
Array.Sort(numbers);
int j = 0;
foreach (int i in numbers)
{
Console.WriteLine("number at place " + (j+1).ToString() +" is " +i.ToString());
j++;
}
Console.ReadLine();
}
static Random _r = new Random();
static int F()
{
int n = _r.Next(0,36);
return n;
}
for horses and chances of winning
static void Main(string[] args)
{
int a = F();
if (a <= 80)
{
Console.Write("horse win!");
}
else { Console.Write("horse lose!"); }
Console.Write(" value of a is " + a.ToString());
Console.ReadLine();
}
static Random _r = new Random();
static int F()
{
int n = _r.Next(1, 100);
return n;
}
|
|
|
|