|
MySQL TinyInt maps to C#'s byte . Use byte.Parse() .
|
|
|
|
|
using strings and sometype.Parse/TryParse is a complete waste, as Dave already pointed out.
all that is required here is a simple numeric-to-numeric cast.
|
|
|
|
|
My apologies. I wanted to ask the OP to use Convert.ToByte() or an explicit cast like (byte)reader["col1"] , but I was carried away by the OP's use of Parse/TryParse . Thanks for pointing out.
|
|
|
|
|
reader["someField"] returns an object of some type, probably byte or sbyte . You can see which by looking at reader["someField"].GetType().ToString()
Once you know the .NET type of the incoming data just do two casts:
(typeYouWant)(typeItIsNow)reader["someField"]
BTWL The alternative of course is to change the field type in MySQL itself, i.e. modifying the database.
|
|
|
|
|
Actually this is not your fault, MySQL reader transforms TINYINT to BOOL by default. In order to prevent this, you need to add the following line to you connection string: "Treat Tiny As Boolean = false".
Just by doing this, TINYINT will be treated as a numeric value
|
|
|
|
|
to get the line of intersection between two rectangles in 3D , I converted them to planes, then get the line of intersection using cross product of there normals , then I try to get the line intersection with each line segment of the rectangle
the problem is the line is parallel to three segments , and intersect with only one in NAN,NAN,NAN which is totally wrong , if you can advice me what's wrong in my code
http://www.4shared.com/file/fAbc3ybd/referenceLineAlgorithm.html
Best regards
|
|
|
|
|
aishar wrote: intersect with only one in NAN,NAN,NAN which is totally wrong No it's not!
To calculate such a line, it has to exist. It doesn't always exist in real life. What is the line of intersection between my desk top and the floor of this room? What is the line of intersection between my floor and your floor? You need a reality check before such a calculation.
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Hi,
I am trying to bone up on my C# skills and have written a new project from scratch. What I am doing is writing a class to simulate a thermometer that returns a temperature measurement and the time of the measurement at fixed intervals. This class will be consumed by a for and the temperature and date displayed on that form as it is updated.
I know that the form cannot be updated by the thread in the Thermometer class because I get a CrossThreadMessagingException
I know that I am somehow supposed to invoke the delegate but in the context of the code I haev written i really don't know how to do that. Could someone show me thow to change the code to achieve this and explain why that code works?
Here is the complete code I have written :
The Form :
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private Thermometer _therm = new Thermometer();
private void btnStartTempReading_Click(object sender, EventArgs e)
{
_therm.OnTempReading += new Thermometer.TemperatureHandler(ShowTemperatureMeasureMent);
_therm.StartReading();
}
private void ShowTemperatureMeasureMent(Thermometer therm, ThermometerEventArgs e)
{
lblTemp.Text = e.Temperature.ToString("00.00");
lblTime.Text = e.TimeOfMeasurement.ToString();
}
private void btnStopTempReading_Click(object sender, EventArgs e)
{
_therm.StopReading();
}
and here is the code for the Thermometer class :
class ThermometerEventArgs : EventArgs
{
public double Temperature
{
get {
Random rand = new Random();
return (rand.NextDouble() * rand.Next(-50, 50));
}
}
public DateTime TimeOfMeasurement
{
get { return DateTime.Now; }
}
}
class Thermometer
{
#region events and delegates
public event TemperatureHandler OnTempReading;
public delegate void TemperatureHandler(Thermometer therm, ThermometerEventArgs e);
#endregion
private System.Threading.Timer _timer;
private Form _form;
public void StartReading()
{
if ((OnTempReading != null) && (_timer == null))
{
_timer = new System.Threading.Timer(delegate(object o) { OnTempReading(this, new ThermometerEventArgs()); }, null, 5000, 5000);
}
}
public void StopReading()
{
_timer.Dispose();
}
}
If it isn't possible to do this with this approach any advice will also be appreciated.
Thank you very much in advance for any assistance.
|
|
|
|
|
See this[^] easy-peasy solution.
/ravi
|
|
|
|
|
Wow, it's that easy?
Thank you very much for the quick and helpful solution.
|
|
|
|
|
Glad I could help.
/ravi
|
|
|
|
|
Unrelated: I recommend creating the Random instance once (as a static field perhaps) rather than instantiating a new one on each call.
|
|
|
|
|
Hi guys!
In one of my applications I use UDP multicast to broadcast event notifications to an arbitrary number of clients.
This works nicely, except for one system where the application is running on Windows Server 2008R2.
On this machine, the call to Send() for a newly created UdpClient hangs.
I'm trying to send around 2K of data, well below the maximum size of 16K for UDP packages.
The process of sending is quite straightforward (at least from my point of view):
- Create a UdpClient
- Join the corresponding multicast group
- Serialize the event data
- Send this data (in row to several destination ports, if this makes any difference)
- Leave the multicast group
I couldn't find anything about Send() hanging so far, but perhaps someone here has an explanation?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi,
Kindly let me know the method or any related link that, How may I insert IMAGE files or JPG,BMP file into MS-ACCESS TABLE using C#
Thank you
(Riaz)
|
|
|
|
|
|
Thank you very much Mr. Peter..
I got the solution from your kind help....
(Riaz)
|
|
|
|
|
hello everyone!!
Help me!!! i want to do the program in the same wiimote but i don't know. if you know, please, help me
Thank you very much
|
|
|
|
|
I think you are a little confused: a wiimote is a controller, not a (normally) programmable device...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Google for wiimote hacks[^] and that will show you what sort of things are possible with the controller.
|
|
|
|
|
There's an article on Coding4Fun[^] that comes with a managed library.
Bastard Programmer from Hell
|
|
|
|
|
Hi All !
I want to use a crystal report ,so i want to add a new data source . when i want to add , i get this Error :
Could not retrieve schema information for table or view
Please help how can i do ?
thanks for any help !
modified on Friday, August 12, 2011 9:15 PM
|
|
|
|
|
|
Hey everyone,
I am kinda junior and was wondering if I could get some assistance with a log class that I am writing.
I am having an issue of file contention when writing/appending to the log from my app while someone else is. Is there a way to get around this?
Everything works fine, the only problem is when multiple people write as described above.
Using: VS2010 C#.
Type : Windows app calling a class library.
Let me know if more information is needed.
Thanks in advance!!
|
|
|
|
|
Typically you don't have multi-user log files for this very reason. Each user has his own personal log file. Each log write operation should open file, write, close file so it is not locked. However, if you are doing a lot of logging, you'll still have multi-user contention. I'd go with a seperate log file for each user.
|
|
|
|
|
sheldons wrote: I am having an issue of file contention when writing/appending to the log from my app while someone else is
The only real solution to that is to stop doing it.
Attempting multiple writes at the same time is not deterministic. And there is no way to make it so.
Multiple apps can use the same file but that requires some mechanism to insure that only one is writing to the file at one time.
|
|
|
|