|
|
wow im a noob thanks lol >.<
|
|
|
|
|
Hello all,
I am using code:
objMyConn=this.DB_Connection();
objMyConn.Open();
objCmd = new OleDbCommand(str_SQL, objMyConn);
objCmd.ExecuteNonQuery();
objMyConn.Close();
When I try using the same SQL in Oracle, it takes 455ms, and if I try running it from .net app, it takes 9-15 min. Should I not use Dynamic SQL for this?
Thanks
|
|
|
|
|
You should never use "dynamic SQL". You use parameterized queries, or risk opening a hole in your code. You have to check for SQL inject attacks, as well as encode your quotes (both single and double) in the parameter values youself. This is why the OleDbCommand.Parameters collection property and the OleDbParameter class exist. Read about them in the .NET Framework SDK. Why it takes so long really depends on a number of factors that your code above just doesn't provide.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi...
I want to write to a Registry key...
I tried this...
try
{
string path = Environment.CurrentDirectory.ToString();
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software").CreateSubKey("SK").CreateSubKey("Info").SetValue("Path", path);
}
catch
{
}
But it throws an UnauthoriziedAccessException that says 'Cannot write to the registry key.'
Can anyone help me?
QzRz
|
|
|
|
|
|
hey - I'm hoping someone on the forum can help me with this. It's a fairly mundane problem, but I can't seem to get around it.
I cannot send an email from an ASP.net application. I get the 0x80040220 error - basically, I don't have permission to send email. Exactly the same code run from a Win32 app works perfectly. A check at MSDN comes up with a slew of solutions, ranging from the vague ("run your web app with correct permissions") to the amazing (download Exchange Server SP3, weighing in at 160+ Megs).
I'm developing a small open source app that needs to send email from an ASP page - I'm looking for a clean and elegant solution to this problem - something I can set in my code without having to ask ppl who use my app to monkey around with their IIS permissions or download a 160 meg "patch".
Any ideas? I'd really appreciate them. After spending weeks banging together my application, it's pretty annoying that it fails on something as trivial as not being able to send out a simple email.
|
|
|
|
|
|
Hi, guys.I am developing an application running in PocketPC. My question is how I can operate the registry of Windows CE. Are there some classes which can be used directly? Or I have to use unmaged code to invoke some API to do that? Could you please to recommend some resources to introduce relevant contents?
Thanks a lot
vigorous
|
|
|
|
|
This question really belongs in the embedded/mobile section however it is easy enough to just answer it here. The .NET Compact Framework does not come with a supported Registry class as is available under the .NET Framework. This said, you will need to P/Invoke RegOpenKeyEx , RegQueryValue , and ExRegCloseKey to have access to the registry.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I have a datagrid that all of its columns are BoolColumnStyle and its DataSource is a table with no relations. I relate this DG with a counter, when I mark true or false in each DataGridCell the counter adds or subtracts (respectively) a certain number. Also I relate a TreeView with this DataGrid that the previous counter works for each TreeNode under the TopNode in this DataGrid. I use this code to make my datagrid to respond to one click :
private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
DataGrid.HitTestInfo hti = this.dataGrid1.HitTest(e.X, e.Y);
try
{
if( hti.Type = = DataGrid.HitTestType.Cell )
{
int r = (int)hti.Row;
int c = (int)hti.Column;
DataRow dr = table.Rows[r];
DataColumn dc = table.Columns[c];
this.dataGrid1[r,c] = !(bool) this.dataGrid1[r,c];
}
}
catch(Exception ex )
{
MessageBox.Show(ex.ToString());
}
} // dataGrid1_MouseUp
I have the following problems :
1. The following message appears. I do not know what is the ListManeger or in other words, I do not understand what is the problem.
2. The DataGrid responds to clicks even when there is no TreeNodes are selected. I want the DataGrid to respond to clicks only when any TreeNode under the TopNode is selected.
3. when the selected TreeNode is changed, I empty the DataGrid by the following code, but the last cell that I add a value to it remains checked :
for(int i=0 ; i
|
|
|
|
|
Anonymous wrote:
The following message appears.
What message is that?
Anonymous wrote:
I want the DataGrid to respond to clicks only when any TreeNode under the TopNode is selected.
Are you checking to see what the TreeView.SelectedNode is at all?
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hy everyone!
At the moment my application avoids double invoking with Mutex and an error message.
But I do want to change this to the following:
When the user starts the application it is displayed.
When the user wants to start a second/third/.... instance of the application this is ignored (maybe even with Mutex) and the running instance is brought back into foreground.
Here is my Main()
<br />
static void Main() <br />
{<br />
bool lstartok; <br />
Mutex lm;<br />
lm = new System.Threading.Mutex(true, "SiemensNameKeyServiceMutex", out lstartok);<br />
if (! lstartok)<br />
{<br />
MessageBox.Show("Service already activ","double invokation",MessageBoxButtons.OK,MessageBoxIcon.Error);<br />
return;<br />
}<br />
Application.Run(new myapplication());<br />
GC.KeepAlive(lm);
}
But now I do want to replace this MessageBox with the popup of the running instance. Meaning instead of the errormessage the running application is brought into foreground.
At the moment I am not sure how to handle this, because I am not sure if I am able to access the running application when the (not allowed) invoking of the second/third/.... instance takes place.
I would have tried
<br />
WindowState= FormWindowState.Normal;<br />
Show();<br />
But well, does this work or how do I "tell" the application to do this to the running instance and not to the new instance?
Thanks!
Stephan.
|
|
|
|
|
One way you could accomplish this is to get the handle to the window you want to show with the native method FindWindow , once you have that, call ShowWindow passing the handle to the window and the nCmdShow flag. The following are the P/Invoke signatures you will need:
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- Nick Parker My Blog | My Articles
|
|
|
|
|
I can't add a refernce to user32.dll because it says it is either an invalid COM or dll.
|
|
|
|
|
Stephan Wright wrote:
I can't add a refernce to user32.dll because it says it is either an invalid COM or dll.
You don't use the "Add Reference" button. Like I said, they are native functions, so they are already compiled. The user32.dll is already on your computer, in the Windows\System32 path. I would recommend you read the Platform Invoke Tutorial[^] for more understanding of what is taking place to make these native function calls.
- Nick Parker My Blog | My Articles
|
|
|
|
|
thanks, the code compiles correctly now, but well it does not work at the moment because either the window is not found or my parameters are wrong in the FindWindow.
So I used Marshal.GetLastWin32Error() to tell me, which error was thrown. But well the only output I do receive is "2" as the error message.
Is there a list of errorcodes for this or what does it mean?
I tried to find out about the hashvalues of the handles and there I found out the window has hashvalue 2. But well, why is this an error?
And besides: Do I have to tell FindWindow the full pathname (meaning including the solution) which you do get when moving the mouse over the classname in debugmode or is it enough to just use the classname without the whole thing bevor this?
Do you or anyone else have an idea of what's wrong?
Thanks!
Stephan.
|
|
|
|
|
It works now!
Well the classname has some wired string added to the "selfdefined" name. Some numbers etc.
That was the problem, but with Spy++ I found out!
Well so at the moment just having to manage the window poping up again instead of only being shown in the taskbar again!
Because the window should be brought into foreground when a double invokation was found.
Stephan.
|
|
|
|
|
I managed to do what you recommended, well almost!
I hardcoded the parameters for FindWindow, because I thought it would be the same verytime I start my application.
But I found out it isn'T, the first parameter for example changes everytime I do restart the computer. And besides it's something really strange. I thought my Window was a Form but well there were numbers and other numeric or letters. So I will have to change this to reading or receiving this from the application, but where? Maybe I don't see the wood because of all the trees anymore but I guess I am stuck again. I was able to get the Handle, the hashvalue or whatever but not the Classname of my Form. Well the WindowName isn't the Problem because it's stored in the Form1.Name element and I just have to fetch this.
But where do I have to fetch the first parameter from? Could you or anyone else help me please, to automate it so I could remove the hardcoded thing!
Thanks!
Stephan.
|
|
|
|
|
Stephan Wright wrote:
But where do I have to fetch the first parameter from?
Are you talking about FindWindow ? This assumes you know the name of the window text. There are other methods of getting the window HWND (Handle) however if you are writing the application you should know this (more than likely). Does that make more sense?
- Nick Parker My Blog | My Articles
|
|
|
|
|
Well, as I said before I should be able to get the name of the window with the Form1.Name field. What I wanted to do is trying to get the classname for my window.
Because it is something like WindowsForms10.Window.8.app88 and that's what I do not want to hardcode because this changes everytime I reboot my PC. It could be WindowsForms10.Window.8.appdd as well.
With "second instance" I ment the user shouldn't be able to invoke the same application on the same PC twice, e.g. by clicking twice on the button. If he does the running application should reappear.
So because it's the same application (but just a second instance) the classname has to be the same. So the second invokation would have the same classname (prooved via Spy++) so I should be able to get the classname from somewhere. But I am not sure where to fetch it.
I also have a mutex on the instance, maybe I could fetch the Handle from there if it is possible to use it in this context.
Stephan.
|
|
|
|
|
what about if you just do the following:
add the handle hash in the registry and evey other application will be able to check it. And if it matches then the application is running. Or if the value is set, then the application is running.
But do not forget to reset the value, because otherwise you won't know if there is an application running or not!
|
|
|
|
|
i downloaded and install project GotoFunction, and after i recompile source code and build new setup project for addin GotoFunction, the install package doesn't work. It doesn't add to menu Tools and doesn't appear in Add-In Manager. Please help me.
Thank you
nthevu
|
|
|
|
|
Your problem is very vague, have you looked through the code that you downloaded, what is it doing? Have you contacted the author of the code/article, what did he/she say? If you have a specific C# question many on here would be glad to help you.
- Nick Parker My Blog | My Articles
|
|
|
|
|
hi,
Actually i posted one queary that " How we will change the color(caption color) of a Tabpage". Unfortunately i forgot to post the answer here. So Here is the answer for " How we will change the color(caption color) of a Tabpage.
Who is going to draw ?
Tabcontrol have a properties called DrawMode. This will set or get the value that whether user or system will paint the caption.By default it is normal. Means system(OS) will paint the caption for you. If you(parent form) want to draw the caption you have to set the value of the property to OwnerDrawFixed.
You can mention DrawMode on design time or runtime like below mentioned code.
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
Now you mention who is going to draw the caption.
Next thing is how is going draw ?
Tab control have an event called DrawItem event which will occure when ever an area need to be painted.
eg:
this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Font f;
Brush backBrush;
Brush foreBrush;
if(e.Index == this.tabControl1.SelectedIndex)
{
f = new Font(e.Font, FontStyle.Bold | FontStyle.Bold);
backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.Blue, Color.Gold, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
foreBrush = Brushes.White;
}
else
{
f = e.Font;
backBrush = new SolidBrush(e.BackColor);
foreBrush = new SolidBrush(e.ForeColor);
}
string tabName = this.tabControl1.TabPages[e.Index].Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
e.Graphics.FillRectangle(backBrush, e.Bounds);
Rectangle r = e.Bounds;
r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
e.Graphics.DrawString(tabName, f, foreBrush, r, sf);
sf.Dispose();
if(e.Index == this.tabControl1.SelectedIndex)
{
f.Dispose();
backBrush.Dispose();
}
else
{
backBrush.Dispose();
foreBrush.Dispose();
}
}
}
Sory for this late posting
**************************
S r e e j i t h N a i r
**************************
|
|
|
|