I have to tables that I have joined together in sqlserver and I am trying to pull columns from both. However, myReader only picks up the first table's columns and i cannot retrieve any columns from the second table. How do I retrieve columns from multiple tables? Here's what I've got. Also is there just a way to type in the column names when retrieving data as opposed to specifying the column id. All suggestions welcome. thanks.
Yeah, it's possible to bring back the data by name but not the way you are doing it unfortunately. Not sure why MS do things this way but if you use:
agencyphone = myReader["YourFieldName"].ToString(); it should work (it's fine for strings but a pain for other datatypes)
I'm not sure why you only get one table's worth of fields back in the query, what does it do when run in query analyser /SQL Management Studio?
Depending on how many rows you have in each table and the width of the table it is often worth using DataRelations in a dataset to join on the client side, this can reduce the weight of data that you pull down the wire consderably.
I have been working on a Windows forms application that lets you list active user sessions on a server/pc.
From there it will allow to :-
connect to a user using vnc/rdp/etc
Log off user
Kill remote running programs/processes
Connect to drive(s) of local machine
Connect to users home folder
List various WMI classes on the PC that user is connected to
I could list more.
But, I am trying to gauge how much interest there might be from others in helping out on an open source c# project that will utilize Windows Forms(using GridView/ListView heavily), WMI and Active directory. That will create a tool that can manage PCs/Users without the need to install local agents (although this may be added later).
I have written the code for all of the above functions already and I have lots of other functions/features to add.
It would be really great if there was any interest from someone in the community to help me develop this application further as an open source project.
This isn't really a good place to ask this question, since it's not a specific C# related programming question; maybe try under Collaboration, but I suggest either just creating a SourceForge.net project or put it up on CodePlex and go from there ...
You could always, after posting it to one of those two boards, come back and announce the project via your "CP Blog".
I have a class1 and in one of its methods I created a local instance of class2 passing to its ctor a member var of class1.
Within class2 I modified the parameter passed to its ctor. To my surprise when I returned to class1 its member var was also modified? C++ wouldve handled this as a local var within class2. What's going on here?
you are passing a reference to the object by value, not the object itself by value. This has often been a source of confusion as it appears at first that value types and reference types behave differently. If you used a struct instead i suspect you would see the behaviour you were expecting.
It's one of those things that is very hard to explain so i'm not going to try right now as I'll probably just confuse the issue. There are a couple of articles around the place if you google for something like 'c# reference pass type by value' or similar you should find a more eloquent description of what's happening than i could provide.
if you create some objects (a Pen, Brush or any other instance of a class that has
a public Dispose() method) inside your OnPaint method, you MUST call Dispose for them.
Additionally, if you need the same object over and over (such as new Pen(myColor)) then
I suggest you create it only once and keep it in a class member (rather than continuously
creating and disposing and collecting them).
And finally, if the objects you need correspond to system objects (such as the ones
available in SystemPens, SystemBrushes,...) I suggest you use these (without new,
without Dispose !).
And I do not recommend you call GC.Collect at all (the gc works fine all by itself),
and certainly not from inside any OnPaint method ! (GC.Collect is expensive and
should not be called by the UI thread, it might ruin the responsiveness).
if you mean Control.Update() I dont know why you think you need it. In all the programs
I have ever developed I never felt the need for it: correct program design (including
the use of background threads for longwinding tasks) results in good responsiveness
On the other hand, Update does NOT cause memory leaks; only errors in your code
( or in .NET itself, rather unlikely) can do that, e.g. not calling Dispose().
If you want us to be able to help you, you should explain more about your app,
and publish the pieces of code you suspect yourself, rather than using
obscure observations (a very big space of memory, unreachable code, bad effect).
ok you are right i am making a packet that moved on a line
when i click a button and stopped when i click stop
so i use thread but the stop button be not responsive and the app hang up
so one here advice me to use BackgroundWorker so i use it but i have a very large consuming of memory when i click the first button i donot no why so i try to solve it hardly
so last i remove update then the memory consuming decreased but not every time i start my application run i work well
some times it work bad so i tried also
so to ask a question if i called a method for a thread or backgroundworker and in this method other method is called
the second method would be run by the program process or by this thread
if by program then i will correct my code
i will publish the pieces of code to see(i miss understanding)
I did not understand very much of what you wrote.
It seems like you want some animation to start when a "Start" button is pressed,
and stopped when a "Stop" button is pressed, and furthermore the "Stop" button does
not (always) work reliably.
There can be several causes for this:
- you might be doing too much stuff in the UI thread
- CPU load might be high at or above the priority of the UI thread
- some logical error in the communication bewteen the "Stop" button handler,
and the thread that does the animation.
Maybe this info will help:
methods are executed on the same thread as the code that calls them (unless you
do very special things, such as calling Invoke). Some asynchronous stuff is executed
on another method automatically (e.g. a tick handler for all timers, except a
if you try to modify the user interface (i.e. add/remove/modify a Control) from
a thread other than the UI thread (the one you have at start) then:
- under .NET 1.1 your program may freeze, or behave unpredictably
- under .NET 2.0/3.0 you will get some "CrossThread" Exception (you could set some
flag false to skip the checks, but then the app may freeze again).
You may want to create your own background thread, so you can fully control it
(set priority, kill/abort it, etc).
You may want to find and read an MSDN article entitled
"How to: Use a Background Thread to Search for Files "
which probably explains more on InvokeRequired, Invoke, threads, etc.
your code contains this.CreateGraphics() which CREATES a Graphics, and hence
requires a matching Dispose() which is not present. I expect this is your main problem.
I dont see how exactly your backgroundworker is working, how iterations are achieved,
and how the drawing is handled by the UI thread; so there might be additional
causes for problems.
ADDED: drawing a packet should be part of your paint handler (so it gets called
whenever anything needs to be repainted, i.e. also when something that was temporarily
hiding your form gets removed, or when your app gets restored from being minimized);
your animation should just modify the parameters that control the drawing
(such as coordinates) and then make sure a repaint gets ordered (typiucally by
actually i wanna to thank u for ur efforts to help me.
first i think the problem is that i donot understand
BackgroundWorker well (it is very complicated)
so i tried before using it to use normal thread but i failed
but now i knew my error and i fix it in the normal thread not the BackgroundWorker Thread and now no(unreachable code,memory leak ...)these things are not found now