|
The value of mm is the same as the value of nn. You are cutting the time part which is the most important here. You should check dates between this interval [15.12.2009 00:00:00.001 - 15.12.2009 23:59:59.998] (and change the format in desired culture)
I didn't notice that this question is re-posted! Man this is kind a rude! You've already got a good answer, so why re-post ?!
|
|
|
|
|
Can someone explain the difference between:
lock (someobject) {}
Using Mutex
Using Semaphore
Using Monitor
Using Other .Net synchronization classes
I just can't figure it out. when to use what ?
|
|
|
|
|
|
DateTime mm = dateTimePicker1.Value;<br />
DateTime nn = dateTimePicker2.Value;<br />
SqlCommand SCD = new SqlCommand("select * from table_inf where tim>= @mm and tim<=@nn", Conn);<br />
SCD.Parameters.AddWithValue("@mm", mm);<br />
SCD.Parameters.AddWithValue("@nn", nn);<br />
<br />
<br />
sqlDataAdapter1.SelectCommand = SCD;<br />
sqlDataAdapter1.Fill(DT);<br />
Conn.Open();<br />
dataGridView1.DataSource = DT;
when i chosen dateTimePicker1 on today and chosen dateTimePicker2 on today too,it can't select Today'data....when you want to select today'data,you must change dateTimePicker2 on tomorrow,it's trouble! How can i chosen dateTimePicker1 on today and chosen dateTimePicker2 on today also can chosen Today's Data!
i don't know how to change my Code ,thanks to everyone!
i,m poor in english,sorry
i use DATA sql2000
|
|
|
|
|
Our problem is that you have he following being executed...
WHERE tim >= 01-DEC-2009 00:00:00 AND tim <= 01-DEC-2009 00:00:00
(or something like that)
because DateTimePicker.Value is a DateTime not a Date.
SO you need to convert your mm to truncate the time portion and your nn to truncate the time and add one day, and change the WHERE to
WHERE tim >= @mm and tim < @nn
(i.e. use less than not less than or equal to)
If DateTimePicker returns the date with a zero time (i.e. midnight on that day) then you just need to change the <= to < and change
SCD.Parameters.AddWithValue(@nn, nn.AddDays(1))
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
thanks,that's it
i' ll do it
|
|
|
|
|
When you sleect the date from the DateTimePicker, it takes the selected date and the current time as the slected value. Now, in your query, say I selected date as 13-Dec-2009, the value that will be sent is "12/13/2009 10:42:54 AM". So, when you select same values in both the datepickers, the query will look like this:
select * from table_inf where tim>= '12/13/2009 10:42:54 AM' and tim<='12/13/2009 10:42:59 AM'
(Five second gap assuming it itakes you 5 seconds to select date in both the date pickers)
Now, this query will search for reacords that fall under that 5 second period and hence you are not getting any result.
You should make use of DateDiff method of SQL and compare only the date part.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Hey everyone,
I'm looking to allow a user to input a mathematical function (like x^2 + y^2 = 4) and graph it on the screen. I've been thinking about how to go about this, and I'm not sure if there is an easier way. Currently, I'm thinking about forcing the user to input the function in the form of y=something and then looping through all of the x-coordinates, solving the right hand side each time for each x-value and then pairing the x and y coordinates together, and drawing lines between each pair. However, this is very clunky, and doesn't allow for three-dimensional equations (when I get there). Is there some way of parsing through the equation and solving it? I know it can be done, because I've seen math programs out there that can graph equations no matter how you input them (including 3D ones). If there is somewhere I can go to learn more about this process, I'd love to hear about it, and if anyone knows of some example code, that would also be appreciated.
Thanks!
|
|
|
|
|
I can think of 2 ways to do what you want and I've used both methods, although there may be other ways.
1) Write a parser and an evaluation "engine" class. The last time I did that I based it on the Forth system so it's real fast, but I converted the system to regular algebraic rather than reverse polish notation. I'd post a link, but the last time I did that I wrote it in Pascal, not C#, and I don't have a link to any code handy.
2) Use the CodeDomProvider class to write the function in the .NET language of your choice. For users I generally stick with VB since users seem most familiar with that. I've also used JScript, C#, F# in addition to VB. My article ScriptEngine - User Defined Calculations in C#, VB, JScript and F#[^] provides an example of how to do this, but you will need to modify for your own purposes. Note, that as mentioned in some of the comments, there doesn't appear to be a good way to ever unload the code if you have a long running application.
In either case you can allow more than just a simple formula, depending on how you limit things. You'll still need to evaluate the function for all your input values and handle the graphics.
Perhaps someone else will have additional ideas. Good luck!
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Hi All,
My teacher stated - "Using public variables in a class will allocate memory for the lifetime of an application. So we should use private variables and use Get/Set." I believe that this is false and the get/set actually add some memory.
Forgetting what is better programming practice, is he right about the memory?
Signed,
Puzzled in C#
|
|
|
|
|
No. What he said would apply to static variables, those exist and cost memory from the first time the class is touched to the end of the app's execution.
public/protected/private doesn't change the cost. Adding properties is adding code, hence costs memory and disk space, however it is a good practice.
|
|
|
|
|
Does adding a property with a simple Get/Set to a private variable actually add to the cost of the runtime?
I remember hearing in Delphi that the compiler had the smarts to compile a simple property exactly as if the private field had been accessed publicly - i.e. without overhead.
Sure it takes a few bytes of source code, but I wonder if there really is any cost to the executable?
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
at the IL level a property "xyz" gets compiled as a get_xyz() or set_xyz() method. the JIT compiler might inline that, I don't know if it does so.
|
|
|
|
|
It should, since the body of the method will be smaller than 16 bytes
|
|
|
|
|
there are lots of things a compiler should do.
In my experience comparing actual behavior with a published list of features and qualities tends to be very disappointing.
|
|
|
|
|
True
|
|
|
|
|
What is the difference in critical section, Mutex and Semaphore ?
When we use Mutex and when Semaphore ?
|
|
|
|
|
This is not a homework forum, but I'll be nice today...
A critical section is a piece of code which is not multithreading safe. It may not be interrupted.
You use a Mutex to reserve a ressource that can be used by exactly one thread at a time.
You use a Semaphore to reserve a ressource that can be used by a finite count of threads at a time.
Now, get back to your books or Wikipedia.
This statement is false.
|
|
|
|
|
Hi
Im new to C# and serial programming.
I need to write a program which monitors the serial port.
i need help to
i need to check whether a port is used by any other application , and display the results???
any help would be greatly appreciated.
Ani
|
|
|
|
|
Hi,
you should learn C# before trying serial interface programming, as that isn't a very simple matter.
you can get the names of all existing ports through SerialPort.GetPortNames().
you can test a port for availability by creating an instance with new SerialPort(portname).
There is MSDN documentation on the SerialPort class (as for all others) that would explain it.
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
{
addItem();
}
private void addItem() {
String [] ports = SerialPort.GetPortNames();
comboBox1.Items.AddRange(ports);
}
private void button1_Click(object sender, EventArgs e)
{
String pName = comboBox1.Text;
// MessageBox.Show(pName);
SerialPort sp = new SerialPort(pName);
/*if (sp.IsOpen)
{
MessageBox.Show("port is already opened");
}
else
{
MessageBox.Show("port is available");
sp.Open();
}
**/
try
{
sp.Open();
}
catch(Exception ee)
{
label3.Text = "the port is not available";
// MessageBox.Show( "the port is not available");
}
}
Hi thanx for your reply.
i wrote this code, but i dont want to open the port, i want to check whther the port is available. when i do the isopen check it says the port is not opened, but im connected through hyper terminal.
|
|
|
|
|
Are you actually connected to the port with Hyper Terminal, or do you just have the program running with the port selected? HT may not set the Open property on the port until you make a live connection with a remote device, and the port would continue to be available until that happens. Try opening the port with your program, then making a connection with Hyper Terminal using the same port. HT should give you an error message if your program has successfully opened the port.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
hi thnx for the help
i resolved the prob
|
|
|
|
|
aniarun wrote: i resolved the prob
Care to share the secret? I might need to use the Serial class one of these days.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
hi
i am not sure whther this the correct solution. but for now prob is solved i used wmi properties to solve
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_SerialPort");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_SerialPort instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]);
Console.WriteLine("port name {0}", queryObj["DeviceId"]);
int i= Convert.ToInt32(queryObj["statusInfo"]);
if (i==3)
{
Console.WriteLine("port is available");
}
else {
Console.WriteLine("port is not available");
}
}
i wrote all the properties to an text file and compared the values when the port was open and closed
/*foreach (PropertyData prop in queryObj.Properties)
{
Console.WriteLine("{0} - \t {1}\n", prop.Name, prop.Value);
tw.WriteLine("{0} - {1}", prop.Name, prop.Value);
}**/
//tw.Close();
statusinfo had value 3 when the port was opened , thts wht maed me use that as the conditional case.
any1 has better solution for this???
|
|
|
|