|
I second that. It's bad enough some clown on the town/community forum for my area loves to do this to keep old, dead threads, alive. I think the chap is still trying to figure out what FFS means
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I need to get sql command text where parameters are replaced by values.
I tried code below but displayed sql statement contains parameter names,
not actual values.
How to obtain command where parameters are replaced by their values ?
Andrus.
static IDataReader ExecuteReader(string command
, out IDbConnection connection
, CommandBehavior behavior
, params IDbDataParameter[] dataParams)
{
connection = ...
connection.Open();
IDbCommand cmd = new SqlCommand(command, connection as
SqlConnection);
foreach (IDbDataParameter p in dataParams)
cmd.Parameters.Add(p);
MessageBox.Show(cmd.CommandText);
return cmd.ExecuteReader(behavior |
CommandBehavior.CloseConnection);
}
Andrus
|
|
|
|
|
As far as I know you can't get the actual command text that is executed programmatically. With sql server you can use sql server profiler to see the command being executed.
|
|
|
|
|
There is a tricky way to do it.
ADO not seems to help providing the SQL query with the proper values prior running.
Here my code snippet that will do the job and may be easily converted any other .NET variant. It's a simple example but may be a start.
Some basic checks were done regarding quotes and backslashes but for sure this code need some care before use on production enviroment.
Note: You will need to change the type SQLiteCommand/SQLiteParameter to the one that matches your ADO methods set.
public static string getQueryFromCommand(SQLiteCommand cmd)
{
string CommandTxt = cmd.CommandText;
foreach (SQLiteParameter parms in cmd.Parameters)
{
string val = String.Empty;
if (parms.DbType.Equals(DbType.String) || parms.DbType.Equals(DbType.DateTime))
val = "'" + Convert.ToString(parms.Value).Replace(@"\", @"\\").Replace("'", @"\'") + "'";
if (parms.DbType.Equals(DbType.Int16) || parms.DbType.Equals(DbType.Int32) || parms.DbType.Equals(DbType.Int64) || parms.DbType.Equals(DbType.Decimal) || parms.DbType.Equals(DbType.Double))
val = Convert.ToString(parms.Value);
string paramname = "@" + parms.ParameterName;
CommandTxt = CommandTxt.Replace(paramname, val);
}
return (CommandTxt);
}
Bruno Ratnieks
CTO Sniffer.net
bruno@sniffer.net
|
|
|
|
|
Hello
I want to detect a mouse StandBy state
I presume that I can do that by combining the MouseMove event and a timer event
But I have no experience with timer event in Csharp
So, before to re-invent the wheel Im looking for some example / suggestion
Thanks for any help
|
|
|
|
|
With forms there's the Control.MouseHover Event.
To implement your own, something like this maybe...
How to detect NO mouse movement[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Timers are easy, don't worry about that.
I'd say create a timer and start it then leave it running until your application closes.
Inside the callback for the Tick event increase a counter, if the counter is above a certain value then you can do whatever it is you need to do. Inside the MouseMove event, reset the counter to 0.
Timer Demo[^]
All you really need are the 4 lines at the beginning of the constructor, and you can just add a timer in the designer too, and set it up there.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Thank you SK Genius
Yes it sounds simple I'll try that
However I do not really see what the other solution "Mouse not move" is doing beside this one
|
|
|
|
|
Mark just made his post as I was still writing mine, either way would work just fine.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Hello SK Genius
Your method sounds good !
A little question
I have the Idea to use the timer only when the mouse is on the concerned control
So I will do a Timer.something(); for the MouseEnter and a Timer.anotherthing() for the mouseLeave
The question is what thing :
Timer.enabled=true;
or
Timer.Stop();
What is the difference ?
|
|
|
|
|
Did you completely ignore my post?
Did you look at the code at the link I provided?
Are you using Windows forms? If so did you know mouse hover
functionality (which is what you're doing) is built in?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark
I'm sorry
No No I do not ignore your post but I thought that the other solution mentionned was similar to yours
For mousehoover : I 've tried this event a few month ago on a picturebox but discard it
As far as I remember I've found that MouseHoover only trigger once at the first stand_by on the control after entering the control. To get another MouseHoover I have to leave the PB and reenter
But maybe I'm wrong ???
|
|
|
|
|
|
Hello Again Mark
Ok I understand now that you are using Stop() / Start() sequence to reset the timer
But it is very similar as the counter ... No ?
My other question remain : what is the difference between Start / Stop
and
enable / disable
|
|
|
|
|
baranils wrote: But it is very similar as the counter ... No ?
I'm not sure what counter you're referring to - I missed
something somewhere
baranils wrote: what is the difference between Start / Stop
and enable / disable
No difference that I see besides Enabled being a property and
Start/Stop being methods.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
SK Genius suggest to use a counter
Increment the counter at every Tick interval
Reset the counter at every MousMove
I like this method because it allows to decide wich action to take depending of the counter value
Fast action for lowest counter
Much time consuming action for higher counter
|
|
|
|
|
Ohhh - Got it, thanks
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello
I one more Question
Now I catch the MouseNotMove event
How can I get the MousePosition on my picturebox at that moment ?
|
|
|
|
|
One way is use the Cursor.Position property followed by
the Control.PointToClient() method.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes got it too !
But when I try it first I thought it does not work because in debugger the mouse was still active and I was getting another position that I was expecting !
Good to know !!
|
|
|
|
|
I have been trying to do this for some time now, and at one time, before I gave up, had code from 2 different people, 1 in VB for detecting the thumb drive being inserted, and 1 in C# for suppressing Autorun.(Could have been the other way around.) Since then, I have lost both files, and I'm simply wondering if it is possible to code something in C# to do both, and then run a program on that drive(PortableApps). My biggest problem is that I know very little C# or any other language for that matter. I do have a friend that is really good at it, but he hasn't been able to figure it out either.
Thanks in advance, for anyone who takes the time to read this.
|
|
|
|
|
This article covers device insertion detection, not sure about preventing autorun, however.
Regards,
--Perspx
Don't trust a computer you can't throw out a window
-- Steve Wozniak
|
|
|
|
|
thanks for the tip. The autorun suppression has proven to be a problem, as nobody seems to be able to code it in C#, only VB.
Does anybody have a solution to this?
|
|
|
|
|
hi,
this is exactly my first program, i will be using C#. The device i am using is a usb connected PC digital TV receiver this receiver software actually have a function which measure the signal strength, BER and these data are save into an log file (thus it real time measurement data) once i start the device (start watch TV).
I am suppose to use C# to get the real time measurement and convert it into graphic (line chart).
I have try to get the data for the log file and display it in the textbox using the following code
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Testing_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
StreamReader objstream = new StreamReader("c:\\measurement.log");
textBox1.Text = objstream.ReadToEnd();
}
but this is the error i got : the file been use by another program.
I also try another method which is directly from the usb port which the device is connected to but i am unable to start working on it coding. i had been looking into example of usb_hib and ICSHARPUSBlib but i was unable to get anything out.
Thus please help me, if i am in the right direction (get the data from usb directly?) or do you have any better item on how i should get this done, any code to refer to.
thank so much
|
|
|
|
|
Because your new here and to programming i wont be too sarcastic but here area a few pointers when posting here...
1.) Please use a subject related to your question
2.) Please use pre tags when posting code
Have a look at my article - How to use the code project forums[^]
Now on to your question
Your trying to get the data from a flat text file, and these can only be accessed by one program / thread / object at a time. Thats why you get the FileAccessException, because the program that logs the signal strenght is constantly updating the file.
Now that i think about it, you can open a file that a program is writing too and view it in notepad... so u might be able to do this, as long as you dont try to write to the file. What strikes me as strange in your code is your using just the stream reader... maybe this is the problem... try this
FileStream fs = new FileStream(@"c:\measurement.log", FileMode.Open);
StreamReader reader = new StreamReader(fs);
string fileContents = reader.ReadToEnd();
as for the graphical part, have a look at GDI+
it involves the use of the OnPaint(object Sender, EventArgs e) event handler of a component like a panel, because youll be updating it continuously your going to have to paint on a Double Buffered Panel so that it wont flicker!
Well that should keep u busy for a while if this is your 1st C# program, if u have any questions ill be glad to help if i can.
Good luck!
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|