|
What about:
int newNumber = (int)(byte)reader["fieldName"];
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I tried byte as well, still same error, specific cast .... =(
|
|
|
|
|
|
|
Nice try, retard.
What makes you think a web site by and for programmers is not going to have that base covered?
Oh, and by the way, your account will be deleted in the next 30 minutes or so.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Normally, I do not agree with your occasional use of "retard". In this case however, it is accurate and justified. 5!
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."
|
|
|
|
|
Ah, the dreaded inerhtml attack.
|
|
|
|
|
|
A MySQL TinyInt is 1 byte. That type in C# i, obviously, byte.
BTW, why on earth are you converting the returned database value to a string, only to parse it back to an int??
|
|
|
|
|
my friend's db is mysql and I am trying to grab his data and then store the value into my sql db
Im grabbing the mysql data parse into a collect list
its a WCF project
so I created a datamember of int newNumber ...
thats why I need to grab it
int newNumber = (int)(byte)reader["fieldName"];
doesn't work ><
it looks like it is reading as a bool value
cause if i convert it to a string, it will gives false
since in that column, I have values of 0, 4, 6 ,7
|
|
|
|
|
|
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)
|
|
|
|