|
Something I have noticed and not sure if it is a bug in the developer or what. But here is the scenerio.
1) Make webform
2) Place a Datagrid control on it
3) Add and oledbdataadapter and the dataset
4) Since The database will be pointing to the local harddrive by default I have to change the connection string. Like so:
string datapath = Server.MapPath("/bin/csharp.mdb");
this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ datapath;
This works fine but here is the catch.
If i change anything at all on the datagrid like for instance an event like delete
or change a property then all the sudden I no longer have an oleDbConnection at all.
It completely wipes out the code that I typed and doing a search for jet turns up nothing.
Same applies if I add an insert cause by default the datagrid control doesn't have a templated insert. I add one manually
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.insertme);
If i change anything on the datagrid via its properties after making that code addition the line of code will be wiped out. And yes I save the code before modification.
Any ideas? Gets annoying after a while. I typed the strings about 4 times after it wiped them clean and i go heck with this and made a text file where i could cut and paste.
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
Changing anything the designer creates and uses is likely to cause such problems. If you want to continue to use the designer, I recommend that you click the Advanced [...] button under the Configuration category in the PropertyGrid while your connection is selected and add an entry for the connection string to the appSettings section of your Web.config file. This is more robust anyway. If you decide, for example, to move your .mdb out of your web application, you can easily change the connection string to reflect that. Since you're using the OLE DB client for ADO.NET, you could even change the connection string to use a different provider (provided that all your ADO.NET code would work with a different one, which is usually fine for most OLE DB providers).
The designer shouldn't complain and croak now.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
report viwer sql reporting services in code?
|
|
|
|
|
I don't have a lot of experience with SQL 2000 RS yet (we'll be looking more into it in the future when we redesign quite a bit of our codebase), but I did watch the MSDN TV video, Developing Applications Using SQL Server 2000 Reporting Services[^], and I believe this was discussed. IIRC, you can pass parameters via GET or POST data, as well as set parameters using the object model (the managed classes and their members).
More information should be available in the RS documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
yes i got it using the url which was easy but took some finding. I think sql reporting services very good i was getting too many bugs from crystal reports and gave up. but sql is very clean. I do need to get more info on the object way of doing it through the reporting web service. I would like to emigrate my family to the USA and good links on finding a sponser for wrok?
|
|
|
|
|
Hi,
I have a main application (Main), from which i can launch two different applications (App1 or App2). I each case i am minimizing the main (Main) application to trash. But on exiting the applications (App1) or (App2), is there any way to restore the window of the main application without double clicking on the Trash icon. I have a requirement to do so. Can somebody help me on this?
Harihara Subramanian
|
|
|
|
|
The other applications will need a reference to the switchboard. You'll either need to use .NET Remoting in order to show/hide forms or use Windows messaging. At least, those two would be the easiest ways. You could create some protocol and use a socket connection, but .NET Remoting wraps all that rather nicely.
So, if the switchboard registered a WKO (well-known object), the other applications could call remote methods on that WKO. The implementation of that object (having a reference to the main Form ) could call Show and Hide when appropriate, or change the WindowState to minimize it to the task bar (not trash, unless you're talking about some specific region within your application) or restore it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks a lot for the immediate reply. I am a little confused as the main application is a .NET application and for the rest, one writeen in VB and the other in VC++. As the intention behind this usecase is to switch to only one of the application at any instance of time.
There is an executable called 'Interoperator' written in VB to which the main application passes instruction like the context information and the application code (App1 or App2).
I have minimized the main application to the task bar(used the ShowinTaskbar property and set it to false), however i do not know how i can send a message back to the main application window to restore it once the applications (App1 or App2) are closed.
private void App1_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
Trash.Visible = true;
}
Can this scenario be handled without having to do anything with modifying the applications as such by a generic design pattern (Switch board)that acts more like a window manipulator?
Harihara Subramanian
|
|
|
|
|
You didn't mention the other applications weren't .NET applications. Since this is the C# forum - a language targeting the CLR - one can only assume. You should be more specific next time.
You could call FindWindowEx , passing NULL as the first param to use the desktop window's HWND . Find your switchboard by title or classname. That will return you the HWND for your application (an IntPtr in managed code), which you can pass to the ShowWindow API.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks again. ShowWindow API displays the Window only when it is present in the Task bar. It is not able to launch the window that is not present in the Task bar.
The following code snippet is what i used.
[DllImport("user32.dll")]
public static extern long ShowWindow(Int32 hwnd, Int32 ncmdShow);
private void App1_Exit(object sender, System.EventArgs e)
{
p = System.Diagnostics.Process.GetProcessesByName("Framework");
ShowWindow(p[0].MainWindowHandle.ToInt32(),1);
}
However in the main application while launching the other applications i used the below mentioned code
private void App1_Launch(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
both the API FindWindowEx and the usage of process to find the handle returns a 0 (zero) when the window is not shown in the task bar. Kindly help me in this regard.
Harihara Subramanian
|
|
|
|
|
First of all, both parameters of ShowWindow should be IntPtr s. These are native ints, which are processor-dependent - just like the IntPtr (32 bits on a 32-bit CPU/OS and 64 bits on a 64-bit CPU/OS).
Also,don't blindly access p[0] . If, for some reason, the process wasn't found an IndexOutOfRangeException or NullReferenceException (depending on what GetProcessesByName returns when a process isn't found) would be thrown.
Getting the Process is no problem. The reason is the MainWindowHandle is returning IntPtr.Zero is because it doesn't currently have one - the main window is invisible. Either don't remove it from the task bar (via ShowInTaskbar ) or try something else.
You could use a mutex and signal it. Any application can use them. C/C++ and .NET have support already (C/C++ through APIs, obviously, and .NET in the System.Threading namespace - which actually uses the same C/C++ APIs internally). With VB (by which I assume you mean VB6, since VB.NET uses the same .NET FCL as C# with only a slightly different syntax) you'd have to declare these native functions.
When the switchboard starts, you create two mutexes (one for each app, or you could use one with a counter) but don't request initial access. When an applicatio starts, you wait on the mutex (to be signaled). When the other applciations exit, you signal the mutex and the switchboard could make itself visible. You could do this in a loop if you wanted, if a user can switch back and forth.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an idea, but not skilled enough to implement in code. It goes like this, the main application which is a .NET assembly will override the Wndproc method. Tha applications will send a user defined message to indicate that they are done while dieing. The Wndproc will handle this message and take appropriate action.
Will this work? Kindly help me.
Harihara Subramanian
|
|
|
|
|
Simple override WndProc and define a const with your message value like so:
private const int WM_USER = 0x0400;
private const int WM_USER_SHOW = WM_USER + 1;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_USER_SHOW)
{
ShowInTaskbar = true;
Show();
}
} Your other applications should send this message (using SendMessage ) using the same message value (0x0401). The problem is that to send the message to the application, you still need a valid Window Handle. Why, then, did I post the code above? To show you what it would look like if you had a valid Window Handle (HWND ) for your application.
You might instead consider using the NotifyIcon component to "minimize" your application to the system tray ("systray" - where the clock is and possibly other icons). It would still maintain a valid Window handle so that messages to your systray icon are handled by your application. See the documentation for the NotifyIcon component in the .NET Framework SDK for more information. There's also several articles here on CodeProject about it and some alternatives.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If anyone is interested, this is a link to a document at Microsoft's Patterns and Practices - Improving .NET Application Performance and Scalability[^].
The document is a HUGE guide (about 1,120 pages) full of tips, samples, howto's, and checklists for improving the performance of your code using ASP.NET, ADO.NET, Web Services, ... This doc isn't just for professional coders either. The Noobies can get a bunch of information out of it too. Just reading Chapter 12 on 'Improving ADO.NET Performance' can answer a bunch of the recurring questions on the forums.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hiya
Does anyone know how to search for all directories on the C:\\ for a server??
I have a web server on a remote machine and need to list certain directories on that machine. I do have full permissions to the machine.
Have tried this:
foreach (string d in Directory.GetDirectories("\\ip address\\C:\\"))
{
MessageBox.Show( d.ToString() );
}
Thanks.
|
|
|
|
|
You need to use the admin share, C$ (\\SERVERNAME\C#). Recursively enumerating the files will be quite slow remotely, however. You might consider - if possible - using .NET Remoting or some other remote technology to tell the server to search it's own hard drive (much faster) and report back to you the results (whether you're filtering or not, whatever fulfills your requirements).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for that. Only need to search for Directories not files.
Will look into it.
|
|
|
|
|
Could you actually show me how to use this while I am considering other options.
Have tried:
foreach (string sDir in Directory.GetDirectories("ip\\C$:\\"))
{
MessageBox.Show( sDir.ToString() );
}
|
|
|
|
|
I did: \\SERVER\C$. You could also use \\IP\C$. Don't use a colon ( . That's the admin share for a drive, which Windows NT establishes for each local drive automatically. And you don't need to call sDir.ToString because it's already a string.
foreach (string dir in Directory.GetDirectories("\\SERVER\C$"))
Console.WriteLine(dir);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm writing a WinForms application that needs to update its user area on change of resolution by the user. I've overriden the WinProc method of my main form so that I can monitor the changes of the resolution and do what I need to do. Its body looks like this:
private const int WM_DISPLAYCHANGE = 0x007E; // this is the message notifying that the display resolution has been changed
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_DISPLAYCHANGE)
{
MessageBox.Show("Width: " + Screen.PrimaryScreen.Bounds.Width + "\n" + "Height: " + Screen.PrimaryScreen.Bounds.Height);
}
}
The problem is that the Screen.PrimaryScreen.Bounds property doesn't work properly the first time the resolution is changed by the user after the application is started. It returns the previous resolution of the display. Here comes the strange part: all the following changes work fine.
I've tried using the Microsoft.Win32.SystemEvents.DisplaySettingsChanged event but the result is the same. Is there a way to get this right?
10x
K.
|
|
|
|
|
Works fine for me using SystemEvents.DisplaySettingsChanged . If something else is wrong, you could always use the Message.LParam split into low- and high-order bits that describe the new horizontal and vertical resolution, respectively. The new settings are packed and passed as the LParam property of the Message struct.
Also, you could save yourself a lot of typing like so:
MessageBox.Show(Screen.PrimaryScreen.Bounds.Size.ToString()); Just a suggestion.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The thing with the low- and high- order bits works!!! I'm happy now Thanks a lot!
Btw, the DisplaySettingsChanged event handling shows always one and the same resloution - i.e. the resolution after the first change, which I find rather strange. Unfortunately, I cannot currently test the app at resolutions different from 800x600 and 1024x768 as I work on a 15'' LCD and this is all I get out of it
10x once again,
K.
|
|
|
|
|
What version of .NET are you using? I've looked at the IL for 1.0 and the SystemInformation and Screen classes actually handle the SystemEvents.DisplaySettingsChanged event and reset their cache. If, when you get the property next, the cache does not contain data the respective data is obtained, cached, and returned. Somethings definitely wrong there. The monitor would also have little to do with the resolution. You might check for newer drivers, although such a small LCD - and no offense meant - might only be possible to go to 1024x768.
One thing to keep in mind to make your code more portable from 32- to 64-bit processors: use the IntPtr.Size static property to get the byte-width of a native int (which is processor dependent). Shift bits accordingly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I want to implement a class in C#, such that one instance of that object should be alive if there are threads using it. If no thread is using it, then delete the object.
So that the next time, any thread needs this class, it should again be created.
It could have been classic singleton, if it would have been alive throughout.
But the hitch is that i need to kill/delete the object when i determine that there is nobody else using it...
Is Locks/mutex is the way out along with reference count.
Could some body throw some light..
|
|
|
|
|
You could use a Singleton, combined with a Semaphore. Use a GetInstance() method and a ReleaseInstance() method. Increment/decrement the semaphore in these methods, and whenever your instance count reaches zero, release your internal singleton pointer and let the garbage collector have it.
Grim (aka Toby) MCDBA, MCSD, MCP+SB
|
|
|
|