|
|
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.
while (myReader.Read())
{
agencyname = myReader.GetString(13);
agencyaddress = myReader.GetString(4);
agencycity = myReader.GetString(26);
agencystate = myReader.GetString(15);
agencyzip = myReader.GetString(28);
agencyphone = myReader.GetString(22);
}
|
|
|
|
|
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.
Hope this helps,
Russell
|
|
|
|
|
Thanks Russell. By reference the columns by their names instead of their id's I was able to pull the column from the second table. You're a life save. Thanks, Again.
|
|
|
|
|
Hi,
I'm trying to get the parent of a MDI form with this code:
<br />
Coordinator c = (Coordinator) this.MdiParent;<br />
But, after the instruction, c is null (debugger);
Any tips?
Many thx,
Nuno
|
|
|
|
|
how about if you do MdiParentForm mdipf =(Mdiparentform) this.....
|
|
|
|
|
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
Shutdown PC
Restart PC
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.
So any interest/ideas?
|
|
|
|
|
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?
Tia.
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
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.
HTH
Russell
|
|
|
|
|
C# passes objects by reference, but the references themselves are passed by value.
Newbies find this very confusing. I know, 'cause I did.
Cheers,
Vikram.
The cold will freeze our stares
We won't care... Join the CP group at NationStates. Password: byalmightybob
|
|
|
|
|
hi all,
i have a program that make a lot of graphical drawing so it consumes a very big space of memory (i think memory leak)
Is any one know how to find where is the leak comes from
(i means where is the unreachable code)
thanx
Generator
|
|
|
|
|
I always make sure to dispose of Graphics objects as they have a bad habit of causing leaks if not thrown away after use.
liberal sprinklings of the using keyword don't hurt either.
Russ
|
|
|
|
|
hi ,
i draw alot of rectangles(one at each invalidate at a moment )
i draw in OnPaint but in it i cannot make dispose (what can i do)
also where i can use GC.Collect
Generator
|
|
|
|
|
Hi,
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).
|
|
|
|
|
Hi,
from debug of my program i noticed that Update();
is making bad effect and may be the reason of memory leak
so can any one tell me what is the disadvantages of it
thanx
Generator
|
|
|
|
|
Hi,
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
without problems.
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).
|
|
|
|
|
hi,
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
else
i will publish the pieces of code to see(i miss understanding)
thanx alot
Generator
|
|
|
|
|
Hi,
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
Windows.Forms.Timer).
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.
|
|
|
|
|

private void btn_simulate_Click(object sender, EventArgs e)<br />
{<br />
this.btn_simulate.Enabled = false;<br />
this.btn_stop.Enabled = true;<br />
closeThreadRequested = false;<br />
if (!packetsMovingThread.IsBusy)<br />
packetsMovingThread.RunWorkerAsync();<br />
<br />
}<br />
private void btn_stop_Click(object sender, EventArgs e)<br />
{<br />
closeThreadRequested = true;<br />
this.btn_stop.Enabled = false;<br />
this.btn_simulate.Enabled = true;<br />
if (packetsMovingThread.IsBusy)<br />
packetsMovingThread.CancelAsync();<br />
}<br />
private void packetsMovingThread_DoWork(object sender, DoWorkEventArgs e)<br />
{<br />
BackgroundWorker worker = sender as BackgroundWorker;<br />
if (worker.CancellationPending)<br />
e.Cancel = true;<br />
else<br />
dataPacket.simulate(lineArray, closeThreadRequested, ref source_pnt,<br />
ref destination_pnt, packetsMovingThread);<br />
}<br />
private void packetsMovingThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)<br />
{<br />
if (e.Error != null)<br />
MessageBox.Show(e.Error.Message);<br />
else if (e.Cancelled)<br />
MessageBox.Show("Cancelled");<br />
}<br />
private void packetsMovingThread_ProgressChanged(object sender, ProgressChangedEventArgs e)<br />
{<br />
if (closeThreadRequested == false && !(source_pnt.IsEmpty))<br />
{<br />
dataPacket.drawPacket(this.CreateGraphics(), source_pnt);<br />
}<br />
Invalidate(drawingFrame);<br />
}
public void drawPacket(Graphics grfx, Point location)<br />
{<br />
Pen pen = new Pen(type);<br />
SolidBrush solidBrush = new SolidBrush(type);<br />
grfx.DrawRectangle(pen, location.X, location.Y, 4, 4);<br />
grfx.FillRectangle(solidBrush, location.X, location.Y, 4, 4);<br />
pen.Dispose();<br />
solidBrush.Dispose();<br />
}
movePacket method compute next point and call
packetMovingThread(declared object).ReportProgress(100);
Generator
|
|
|
|
|
Hi,
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
calling Invalidate).
-- modified at 17:48 Sunday 8th April, 2007
|
|
|
|
|
hi Luc Pattyn,
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
any way thanx to u very much
bye
Generator
|
|
|
|
|
|
Is there a way to access each of the controls in a form by name programmatically?
i.e. without having to loop through each one
Tia.
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
Yes,
use the Controls Property of a Contailer like Form or Panel:
<br />
Control c = Controls.Find("name", true);
Control c = panelXYZ.Controls.Find("name", true);
|
|
|
|