|
You can use the Replace() function.
Use it before executing the sqlcommand:
It is of the form:
Replace(TheString, WhatToReplace, ReplaceItWithWhat)
So apply it this way on all your variables before inserting them into the sqlcommand string:
Replace(value1, "'", "''")
Replace(value2, "'", "''")
Cheers
|
|
|
|
|
Hi!
I think you really should use parameterized queries. That way you don't have to worry about such things as how to place your quotes and are less prone to SQL injection attacks.
mav
|
|
|
|
|
Is there a way to make VS.net 2005 ignore the "Illegal Cross Thread Opperation" in debug mode?
/\ |_ E X E GG
|
|
|
|
|
Nevermind, this is the solution...
private void button1_Click(object sender, EventArgs e)
{
Thread nThread = new Thread(delegate()
{
int i=0;
while (i < progressBar1.Maximum)
{
progressBar1.Invoke((MethodInvoker)delegate
{
progressBar1.Value = i++;
});
Thread.Sleep(500);
}
});
nThread.Start();
}
"Reason:
The UI controls are not thread safe. Previous versions of .Net would
allow these thread-unsafe to be made, but they will cause weird things
to happen (often resulting in the application just disappearing)
eventually. .Net 2 detects these bad cross-thread calls, and raises an
exception.
When in another thread, you should invoke all UI control methods using
BeginInvoke and EndInvoke rather than directly."
http://www.dotnet247.com/247reference/msgs/54/272634.aspx[^]
/\ |_ E X E GG
|
|
|
|
|
Does anybody know how to put a trackbar in a toolstrip?
/\ |_ E X E GG
|
|
|
|
|
I was looking for a way to capture a window and render it with Direct 3D as my little research on how microsoft create their new hardware accelerated desktop
and i got this from expert exchange
<br />
HDC hdc = GetDC(hwndExplorer);<br />
HDC hdcMem = CreateCompatibleDC(hdc);<br />
RECT r;<br />
GetClientRect(hwndExplorer, &r);<br />
HBITMAP hbm = CreateBitmap(r.right - r.left, r.bottom - r.top, 1, 32, NULL);<br />
HGDIOBJ hbmOld = SelectObject(hdcMem, hbm);<br />
SendMessage(hwndExplorer, WM_PRINT, (WPARAM)hdcMem, PRF_CHILDREN | PRF_CLIENT);<br />
I have tried to convert it (with my little knowledge :S) to this:
<br />
IntPtr victim = API.FindWindow( null, null );<br />
API.GetClientRect( victim, out victimClientArea );<br />
Bitmap b = new Bitmap( victimClientArea.Width, victimClientArea.Height );<br />
<br />
Graphics gB = Graphics.FromImage( b );<br />
IntPtr hdcB = gB.GetHdc();<br />
<br />
API.SendMessage( victim, (uint)API.WMDefs.WM_PRINT, hdcB, (IntPtr)(API.PRF_CHILDREN | API.PRF_CLIENT | API.PRF_OWNED) );<br />
i got blank bitmap from this code ?
Can anyone help me out!?!?
|
|
|
|
|
|
Thanks! The code works, but it require the window you want to capture to be active.
Otherwise, you will get whatever inside the area of that window :S
i change the capture code from:
<br />
GDI32.BitBlt(capHDC,0,0,width,height,wndHDC,x,y,GDI32.SRCCOPY); <br />
to:
<br />
USER32.SendMessage( wndHWND, Constants.WM_PRINT, capHDC, (IntPtr)( Constants.PRF_CHILDREN + Constants.PRF_CLIENT + Constants.PRF_OWNED ) );<br />
and i can capture anything anywhere - even the window is not inside the screen - but the problem is...i can't capture another application's window!!!
what happended this time ???
Do i have to get special permission for my application to send messsage to another window?
|
|
|
|
|
There is a API called PrintWindow.
<br />
[DllImport("user32.dll", SetLastError=true)]<br />
static extern IntPtr PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);<br />
|
|
|
|
|
Hi.. i've been trying to get the status of the battery on my laptop, but cant get the thing to work.
here's my code (in my main class)
public struct SystemPowerStatus
{
byte ACLineStatus;
byte batteryFlag;
byte batteryLifePercent;
byte reserved1;
int batteryLifeTime;
int batteryFullLifeTime;
}
[DllImport("kernel32.dll")]
public static extern bool GetSystemPowerStatus(ref SystemPowerStatus systemPowerStatus2);
private void form_load(object sender, EventArgs e)
{
MessageBox.Show("i want to print the battery % status here - how?");
}
how do i make it print out the battery status in the message box ? Can't get the thing to work
|
|
|
|
|
Try something like the following:
[DllImport("Kernel32")]
private static extern Boolean GetSystemPowerStatus(SystemPowerStatus sps);
[StructLayout(LayoutKind.Sequential)]
public class SystemPowerStatus
{
public ACLineStatus _ACLineStatus;
public BatteryFlag _BatteryFlag;
public Byte _BatteryLifePercent;
public Byte _Reserved1;
public Int32 _BatteryLifeTime;
public Int32 _BatteryFullLifeTime;
}
public enum ACLineStatus : byte
{
Offline = 0, Online = 1, Unknown = 255
}
public enum BatteryFlag : byte
{
High = 1,
Low = 2,
Critical = 4,
Charging = 8,
NoSystemBattery = 128,
Unknown = 255
}
Your usage would look like this for example:
private void button1_Click(object sender, EventArgs e)
{
SystemPowerStatus sps = new SystemPowerStatus();
GetSystemPowerStatus(sps);
if (sps != null)
{
MessageBox.Show(string.Format("Current battery life is at {0}%.", sps._BatteryLifePercent));
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
it gives me an error, which says sps does not contain a definition for _BatteryLifePercent... if I let intellisense show the possibilites of sps it just gives me ToString(), GetHashCode(), Equals and so on
|
|
|
|
|
I've updated the post, I forgot to copy over the class from my project in the post.
- Nick Parker My Blog | My Articles
|
|
|
|
|
looks like its working.. thanks
|
|
|
|
|
What is the ListView's equivalent of ListBox's DisplayMember ?
/\ |_ E X E GG
|
|
|
|
|
Unlike the ListBox control, the ListView control does not have a DisplayMember nor does it have a DataSource, ValueMember or any similar property. Because these are properties inherited from ListControl and ListView control is not inherited from that.
If you're going to implement data binding in a ListView control, you'll have to do so by yourself and depending on the structure, you have to populate the ListView's headers, item collection and -if any- subitems manually.
|
|
|
|
|
OK, thanks.
/\ |_ E X E GG
|
|
|
|
|
Hello! I'm a bit confused with an xml program i'm doing. The program goes through a xml-file wich is designed something like this:
<item>
<title> title </title>
<link>link</link>
<description>description</description>
</item>
<item>
... and so on
when it goes through the file i want it to make an instance of a class called Item everytime it finds the start of an item element, then fill the Item class fields (wich are title,link,description) and then put it in a Item array. But i can't get it to work at all.. Could someone give me some hint or anything?
Thanks!
|
|
|
|
|
Hmm, it seems like my xml-code got wiped! well, the root-elemtent(?) is Item, and then it has elements called title,link,description in it
|
|
|
|
|
Hi,
I'm overriding the ProcessDialogKey(Keys keyData) method of a textbox to handle keyboard input. Does anyone know how to convert the Keys values into characters? The usual letters and digits are no problem (A-Z, 1-9), because:
Keys.A = (int)'A' => (char)Keys.A = 'A'
But I can't handle some of the other keys. For example, if the user hits ";", the result of (char)keyData is some weird character ((char)192).
Is it possible to convert a Keys value to a character depending on the current user's keyboard layout? I don't want to use a large switch statement, because that doesn't consider different layouts (e.g. ";" = "ö" in German keyboard layout).
It has to be possible, because after all, the normal textbox just does that, doesn't it? I tried KeyConverters and some API-calls (toascii), but nothing seems to work right.
Any help would be highly appreciated, because I already spent hours on that (shame on me).
|
|
|
|
|
Interesting problem indeed. I also cannot find a solution. Perhaps try overriding protected virtual bool ProcessDialogChar(char charCode); instead? It gives you the char right away.
|
|
|
|
|
Thanks for the suggestion. But I don't think that I can use that method. What I want to do is a simple textbox control that shows the keys the user pressed, including the modifier keys (alt, ctrl, shift). The output should be something like 'Shift + Ctrl + F' or 'Alt + H' or 'Shift + ;'.
Even if I would use a combination of ProcessDialogKey and ProcessDialogChar, I would receive a ':' in ProcessDialogChar for a "real" 'Shift + ;', because ProcessDialogChar already takes the shift key into consideration. Besides that, some other keyboard layouts already need modifiers for some keys that aren't needed in other layouts (like ';' = 'Shift + ,' in German layout). So this will just result in the same problem I described first, but the other way round (how to get the Keys value for a certain character).
So if possible, I'd rather use ProcessDialogKey and convert the Keys to chars. Anyone?
P.S.: if someone knows how to distinguish the left and right shift/ctrl keys... the Keys-enum contains values for them, but the aren't used?
|
|
|
|
|
Here's a solution. Use the MapVirtualKey function located in user32.dll:
[DllImport("user32", EntryPoint = "MapVirtualKey")]
public static extern int MapVirtualKey(int wCode, int wMapType);
It converts scan codes, virtual keys and characters. From the Win32 api help:
Parameters
==========
uCode
[in] Specifies the virtual-key code or scan code for a key. How this value is interpreted depends on the value of the uMapType parameter.
uMapType
[in] Specifies the translation to perform. The value of this parameter depends on the value of the uCode parameter.
0
uCode is a virtual-key code and is translated into a scan code. If it is a virtual-key code that does not distinguish between left- and right-hand keys, the left-hand scan code is returned. If there is no translation, the function returns 0.
1
uCode is a scan code and is translated into a virtual-key code that does not distinguish between left- and right-hand keys. If there is no translation, the function returns 0.
2
uCode is a virtual-key code and is translated into an unshifted character value in the low-order word of the return value. Dead keys (diacritics) are indicated by setting the top bit of the return value. If there is no translation, the function returns 0.
3
Windows NT/2000/XP: uCode is a scan code and is translated into a virtual-key code that distinguishes between left- and right-hand keys. If there is no translation, the function returns 0.
Return Value
============
The return value is either a scan code, a virtual-key code, or a character value, depending on the value of uCode and uMapType. If there is no translation, the return value is zero.
************
This will do a Keys value to character conversion:
(char)MapVirtualKey((int)keyData, 2)
Regards,
kalme
|
|
|
|
|
Before I even start, I apologize for asking a NON-C# question in here. I've posted questions in nearly every forum in this site, and the responses in this one are by far the best. On that note, here is my question:
We have a situation at work where we've encountered a problem with accessing files which are located on another machine as the IIS server. We're using the File System Object to access these remote files. The problem is that the FileExists function always returns false for a file on another machine. This is a permissions issue, and I have some workarounds for it. Setting up a user account on the remote machine for the IUSR_COMPNAME account isn't really feasible, since this needs to be in commercial software, and the password for this account is generated dynamically. Yes, we could hack the registry and get this, but it's something we're trying to avoid. We could also have the ASP page start an external application to access the file, but again, we have the overhead of starting and ending a separate application, as well as the fact that we have to set up some way of giving this application the names of the actual files to access. I guess my question is, is there a method of doing this which actually works? If I search the web, I see that this issue has come up a lot...and the only real work-around I've seen is putting the IUSR account on the remote machine. Is there another way, and if so, what are the steps, or where can I find a quality article on this topic?
Again, while this isn't a pure C# question, it's still an issue that somebody using C# might face, so it's worth sharing. Thanks everybody.
|
|
|
|
|
I think if you are trying to do this with the ASP code you need to explicitely map the logical path to a physical one before trying the FileExists() function. Search on these lines.
|
|
|
|
|