|
Something like the following should do it:
static void DetachPubsDB()<br />
{<br />
string connStr = "provider=SQLOLEDB;Data Source=(local);User ID=sa;Password=;Initial Catalog=master; Network Library=dbmssocn";<br />
OleDbConnection conn = new OleDbConnection(connStr); <br />
<br />
try<br />
{<br />
conn.Open();<br />
<br />
OleDbCommand cmdDetach = new OleDbCommand("sp_detach_db", conn);<br />
cmdDetach.CommandType = CommandType.StoredProcedure;<br />
cmdDetach.Parameters.Add("dbname", "Pubs");<br />
cmdDetach.ExecuteNonQuery();<br />
<br />
OleDbCommand cmdAttach = new OleDbCommand("sp_attach_db", conn);<br />
cmdAttach.CommandType = CommandType.StoredProcedure;<br />
cmdAttach.Parameters.Add("dbname", "Pubs");<br />
cmdAttach.Parameters.Add("filename1", @"C:\Program Files\Microsoft SQL Server\Data\MSSQL\Data\pubs.mdf");<br />
cmdAttach.Parameters.Add("filename2", @"C:\Program Files\Microsoft SQL Server\Data\MSSQL\Data\pubs_Log.ldf");<br />
cmdAttach.ExecuteNonQuery();<br />
}<br />
catch(Exception excp)<br />
{<br />
Console.WriteLine(excp.Message);<br />
}<br />
finally<br />
{<br />
if(conn.State == ConnectionState.Open)<br />
conn.Close();<br />
conn.Dispose();<br />
}<br />
}
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Thank you sooooooo much, I can hardly wait to give it a try!
Why is it that finding a simple example such as the one you have furnished is so difficult?
Thanks again!
cb
|
|
|
|
|
Actually, it's not so bad.
MSDN has lots of good articles on various facets of ADO.Net and if all else fails, there's Google. I would strongly recommend visiting Microsoft's ADO.Net Primer[^] if you plan to work with ADO.Net a lot.
Most of the challenge that I've seen people suffer through with ADO.Net stems from their previous history with ADO 2.x (COM-based).
The two ADO implementations share some terminology and concepts, but are largely different. Many experienced ADO 2.x developers find ADO.Net syntax more cumbersome than ADO 2.x and I suppose I agree to some extent.
A very good place to start is by examining the ADO.Net object hierarchy. Take the time to read about each class (there really aren't that many, and there are only a handful that get used in most common database transactions).
CodeProject is a great place to get information, but you have to have a mindset that you're prepared to explore and experiment - experience is the best teacher.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Agrreed and thank you.
I have bought several ADO.NET books and am picking it up really quickly. I was doing pretty good until I needed to write an application using an MSDE DB on a distributable CD.
In one sense since my application will be just referencing (reading) the DB my work is easy.
The hardwork is in developing a 'setup' routine that installs MDAC, .NET, MSDE, my application and reference the data on the CD.
This kind of through me into using transact-sql, something I've never needed to do before.
I found plenty of examples of transact-sql statements and I've written qutie a few ExecuteNonQuery() routines but I couldn't find an example that put it all together.
What you pointed out was that my commandtype = storedprocedure which I didn't think I needed.
So with your help and my recently purchased "The Guru's Guide to Transact-SQL" I'll get to experimenting.
Thanks again,
cb
|
|
|
|
|
Printing within C#/.NET seems pretty easy. At least it did until I tried to draw some objects with specific sizes.
During a print page event I try to draw a rectangle 1" x 1". I calculate the size as:
RectangleF r = new RectangleF( 0,0,g.DpiX,g.DpiY );
The rectangle is grossly over sized.
The DpiXY of the graphics is typically 600x600...seems right.
However, I do notice that the page units of the graphics are GraphicsUnit.Display which is not what I was expecting for a print event.
Transform of the Graphics is identity.
Any ideas ?
-Duncan
|
|
|
|
|
Ok, I'll answer this one myself
GraphicsUnit.Display is the default. This implied a 100dpi device.
Thus the correct way to calculate a real world size is:
float dpiXA = g.DpiX * ( 100.0f / g.DpiX );
float dpiYA = g.DpiY * ( 100.0f / g.DpiY );
Then use dpiXA/YA in your size calculations.
If you are doing a print preview to a display device ( typically 96dpi ) then this calculation will also be correct.
|
|
|
|
|
hi,
i have a Mesh that fills all the screen and i want to get a window loaded in the app so i can interact with it as realy active window
can i make my app form is parent for this certain window if yes how ??
|
|
|
|
|
Uhhhh....What?
I can't make any sense of what your trying to do. What are you trying to interact with and how do you want to interact with it?
RageInTheMachine9532
|
|
|
|
|
i want to interact with real windows but in my app (the window must be in my app form(like parent))
but i have another problem that my app is directX app that is loaded with Mesh(Parent)instead of appform.
|
|
|
|
|
I take it you want to edit something in a child window of your Multiple Document Interface (MDI) app? And on top of that, it's a DirectX app?
If that's the case, specifically what's the problem your having?
RageInTheMachine9532
|
|
|
|
|
yes this the problem but the windows is an operating system window("c:","IE")for example
|
|
|
|
|
What????????????????
Mesh??? Another app's windows??? DirectX???
I hate to say this, but, none of this is making any sense...
You want to work in another app like that app's window was in your application? Are you asking how your application can control another application?
RageInTheMachine9532
|
|
|
|
|
yes how can i control another app from my DirectX App??
|
|
|
|
|
Finally! OK. What you ask is not that easy and is problematic at best.
You can look into using SendKeys to stuff keystrokes into the message stream of the app you want. But since the focus can bechanged between the time you activate the app you need to send keystrokes to, or even during sending the keystrokes, the focus can change to another app.
Doing stuff with the applications windows will require you to look into the Win32 API and creating the structures and function declarations for C#. This includes something as simple as moving a window or maximizing or minimizing it. You'll have to use functions like GetWindow, GetWindowPlacement, SetWindowPlacement, SetForegroundWindow, SwitchToThisWindow, MoveWindow, ... plus all the structures that these functions use!
You might want to consider writing the bulk of this code in C++ instead of C# because all of the functions and structures already come in the header files and libraries natively used by C++ to write Windows apps.
Have fun and stock up on some Advil or Excedrin. You'll need it!
RageInTheMachine9532
|
|
|
|
|
Hi,
How can I count the total number of WinWord that is running in my C# application?
Thanks in advance.
|
|
|
|
|
hi see the article of windowhiding
this will get u all open windows then search for (winword) in the windows.Title u will have the count
|
|
|
|
|
yyf wrote:
How can I count the total number of WinWord that is running in my C# application?
The follow will work:
using System.Diagnostics;
Process[] pa = Process.GetProcessesByName("WINWORD");
if(pa != null)
{
int count = pa.Length;
}
- Nick Parker My Blog
|
|
|
|
|
I would just use the tools available in System.Diagnostics.
Example:
System.Diagnostics.Process[] runningProcess = System.Diagnostics.Process.GetProcessesByName("WinWord");<br />
<br />
foreach(System.Diagnostics.Process proc in runningProcess)<br />
Console.WriteLine(proc.Id);
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Thank all of you. This is very helpful!
Here is what I did using Win32API(I import the user32.dll and put it into my Win32API class), but it doesn't work as I except.
public int CheckWord<br />
{<br />
int num;<br />
string lpText = new string((char) 0, 100);<br />
IntPtr hWnd = Win32API.GetWindow(Win32API.GetDesktopWindow(), Win32API.GW_CHILD);<br />
<br />
int UStnNumber = 0;<br />
while ( !hWnd.Equals(IntPtr.Zero) ) <br />
{<br />
num = Win32API.RealGetWindowClass(hWnd, lpText, lpText.Length);<br />
if ( num > 0 ) <br />
{<br />
if ( lpText.Equals("OpusApp") ) <br />
{<br />
UStnNumber ++;<br />
}<br />
}<br />
hWnd = Win32API.GetWindow( hWnd, Win32API.GW_HWNDNEXT );<br />
}<br />
return UStnNumber;<br />
}
Do you know why?
|
|
|
|
|
yyf wrote:
but it doesn't work as I except. Do you know why?
Did you try the code I showed as an example?
- Nick Parker My Blog
|
|
|
|
|
Yes, I did. It works very well. But I just wonder why my way doesn't work.
|
|
|
|
|
I'd like to create a ToolTip in my TreeView that acts just like the ToolTip in Visual Studio Text/Code Editor:
1. Show tooltips for each Node in the TreeView without having to move the mouse out of the TreeView and back in.
2 Show the tool tip until the mouse moves again...
Any ideas ?
|
|
|
|
|
The ToolTip component in the .NET base class can be used if used correctly. Try the following search[^] and find the articles by Nish and ramshri. They suggest one way of doing it.
Since the tool tip control is really just a popup window, you could always create a popup window with no border and perform a lot of the functionality yourself, like resizing it appropriately, etc. For an excellent article that takes this approach for a Balloon Window.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I know that it is possible to view checkboxes at each treenode, but it is possible to hint some of them? For instance my Root-Node should doesn't contain one, but all others.
Any solutions?
|
|
|
|
|
Not with the TreeView in .NET. The Tree-View common control - which is encapsulated by the TreeView control in .NET - doesn't support this either. There are many third-party controls out there like UltraWinTree from http://www.infragistics.com[^], and one from http://www.devexpress.com[^], though I haven't had a chance to use that one yet. We do use the Infragistics control in our application for this and many other reasons because it was far cheaper to use a third-party control rather than spend the time overriding behavior of the existing TreeView or making our own from scratch.
Microsoft MVP, Visual C#
My Articles
|
|
|
|