|
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;
}
|
|
|
|
|
I'll take a bash at a slightly more realistic roulette simulator.
The roulette wheel works by having the ball travel a spiral path at a random velocity in one direction and the wheel spin at a different random velocity in the opposite direction. The number is determined by the degree of rotation of the wheel at the time the ball reaches a point in the spiral at which it touches the wheel.
Now, since i dont have the inclination to find the mathematical formula for a spiral we are going to assume that the ball is moving in decreasing circles.
we are also going to run the ball and wheel in seperate threads, but i'll leave you to sort out the threading
Ball thread:
public int RunAndReturnFinalAngle(int startRadius, int wheelRadius)
{
Random rng = new Random();
int sampleCount = 360;
int currentStep = 1;
int delayTime = rng.Next(10, 100);
int currentRadius = startRadius;
int radiusReduction = rng.Next(1, 5);
double ballX = 0;
double ballY = 0;
int angle = 0;
while (currentRadius > wheelRadius)
{
currentStep++;
if(currentStep > sampleCount){currentStep = 1;}
angle = 360 * (currentStep / sampleCount);
ballX = currentRadius * Math.Sin(angle);
ballY = currentRadius * Math.Cos(angle);
PositionBallGraphic(ballX, ballY);
currentRadius -= radiusReduction;
Thread.Sleep(delayTime);
}
return angle;
}
Now for the wheel, thats a lot simpler, simply run a loop modifying a value between 360 and 0 (remember its going the opposite direction) on a random delay (to set its speed) until the ball thread has done its thing.
At this point you will have the final angle of the ball and the final angle of the wheel.
public int GetNumberIndexForBall(int ballAngle, int wheelAngle)
{
int angleRelativeToWheel = ballAngle - wheelAngle;
return angleRelativeToWheel / 10;
}
Then you can use that index to get the wheel number from an ordered array/list of numbers on the wheel
Its very rough and hasnt been compiled/tested but that should provide a more real-to-life simulation of roulette than a simple random number between 1 and 36 and also give you graphical positioning data for the ball
modified on Thursday, September 1, 2011 4:12 PM
|
|
|
|
|
This sounds very interesting.
I will continue to learn what I am from the book, then I may be able to place this code into context.
Thank you, it seems much better than the standard Rand.next(0,35);
Regards,
Stephen
|
|
|
|
|
if you don't need the ball placement then i would recommend sticking with the simple random.next(), A true random number is not possible (at least generated electronically) but the random.next() is pretty good and any system deriving a random number from logic wrapped around a call to that method is at best going to be equally as good but, more likely, introduce bias (which the code i posted above most certainly does).
I posted that code more as a theoretical exercise in how one might simulate a (simplified) roulette wheel, for a system in which bias should be minimal (such as a gambling game in which real money is exchanging hands) it would be better to generate a random number through random.next() and then, having done this, calculate the animation of the ball (so that the ball itself is merely representing the already generated result and not playing a part in generating it)
Keep reading the book, but don't forget to get in there and get your hands dirty. Nothing teaches programming like attempting to program
|
|
|
|
|
Hi.
This is for fun, and not the real thing. It is going to be my first "real" project after the book. Although I would like it to be as "real" as possible.
I was actually thinking along the same lines.
1) Generate a random number 0-36
2) Animate the wheel, and somehow when the ball arrives near the generated number, make it "bounce a little" as though it was going to (random again) land on the number to the left or right before "faling" into place.
3) Use some kind of list/enum to look up the value and also get whether it is black or red (or green)
I have just started with the book now, and when I finish I am going to give this a real go.
Thank you for your advice and comments.
Kind Regards,
Stephen
|
|
|
|
|
Hi everyone,
Many off you know I ask a lot of questions, and although I am a complete beginner with c#, it is simply for the fact that I am impatient and want to get on with it, however, I now realise that I need to sit down with a good book.
Anyway, I have just purchased "Head First C#" 2nd edition.
I selected this book as some of the real-world projects appealed to me.
I would like to know if anyone has any experience with this book, and if I have made a good choice for a first book, and if I am likely to learn much in the way of windows development with c#?
Thank you,
p.s. LucPatton, if you are reading this, I am sure you will be happy (and relieved) that I finally got a book
|
|
|
|
|