|
I have an application that needs to retrieve data from a database using a left join query. The left join, of course, may return null values from the "right" database table (call it table2) if a matching record is not found in table2.
This can cause a problem because I have fields on my form bound to the values in the DataTable filled by the SQL query. I handled this problem by running through each line in the resultant DataTable and replacing any null values with an appropriate default, but this operation is relatively time consuming.
Is there a better method to set the default values on the DataTable.
Thanks.
|
|
|
|
|
Yes, in the query use the ISNULL() or COALESCE() SQL Server functions and provide the default values that you want there, then you don't have to do anything with the resultset in code.
Keep It Simple Stupid! (KISS)
|
|
|
|
|
Thanks. The application I'm working with uses Access, so I think I need to use IIF with ISNULL() to make it work with this software, but that's exactly the idea I was looking for. I wanted something that could work quickly, without iterating through the rows of the table or doing anything else in the code. Thanks.
|
|
|
|
|
Hello,
I have encountered a problem trying to draw a line with a custom pen.
What I need to do is draw a line from point X to point Y, but use a certain shape (some polygon), as opposed to the standard pen I get in DrawLine(Pen, Point, Point) interface.
There is the PenLineCap, but it is not good enough as it supports specific shapes.
Anyone has any idea how to achieve this?
Thanks!
|
|
|
|
|
I don't understand what you mean by a "custom pen". You create a Pen object with a color (or a brush) and a width, and then use it to draw something (a line or a shape). I don't do new Pen() in a method call because you have to dispose the pen when you're done with it.
Pen pen = new Pen(Color.Black, 1);
Point point1 = new Point(0,0);
Point point2 = new Point(10,10);
Graphics graphics = Graphics.FromHdc(this.Handle);
graphics.DrawLine(pen, point1, point2);
graphics.DrawImage(bimap, blah blah blah);
pen.Dispose();
graphics.Dispose();
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Thanks for your reply, but that is not what I meant.
What I need is to draw a line with a "star" shape for instance.
I mean, use a custom shape (any polygon/ellipse) in order to draw a line with it.
Take a look at the picture to see what I mean.
http://img242.imageshack.us/my.php?image=sampleiw3.png[^]
Thanks everyone!
|
|
|
|
|
Here's a codeproject article about drawing the US flag, which includes the code to draw a 5-pointed star:
http://www.codeproject.com/KB/cs/DrawUSFlag.aspx[^]
I found this with the following google search:
c# gdi+ draw a star
It's not so much a custom pen as it is a custom polygon shape.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
|
|
For god sake man, have you not listened to ANYTHING you've been told today?
|
|
|
|
|
Stop asking and read you previous responses. Can you read?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
What the hell man, people aren't going to code for you, you've been answered 12 times! Get started already or quit.
|
|
|
|
|
Help[^]
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Oh dear. I can't stop laughing....
Simon
|
|
|
|
|
That's the most useful web page I've ever created. It's kinda like that commercial that ends with the line "...but I did stay at a Holiday Inn Express last night." - you eagerly await an opportunity to use it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I Lol'ed out loud at work. Thank you for that. I feel like an idiot now because 15 people saw me burst into laughter.
You sir, get a well deserved 5.
|
|
|
|
|
John john john
Brilliant! Thank you for that. Does that page have a licensing agreement or are we free to use it?
Seriously, if you plan to keep that running it could easily be my most frequently posted link here in the forums.
led mike
|
|
|
|
|
You are free to use/duplicate it. It's been available since about 1998, and right now, there's no plan to take it down.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I've got a txt file I'm parsing and need to extract specific lines from it and copy them to another file. First I scanned the file for the lines of interest by using the readline function. Each time I got a line I'm interested in I inserted the line number into an array.In the end I got an array that holds the line numbers of the lines I'm interested in coping. Meaning, the start line in one cell and end line in another, and I've got several of those in the array.
How do I copy the block of lines (between 2 cells listed in the array )from one file to a new file? Do I need to sync the StreamReader of one file with the StreamWriter of the other? or are there any other better ideas as to how to do it?
Thanks in advance,
Inbal
|
|
|
|
|
Rather than only holding the line numbers in the array. Make it a string array*, and store the whole line in the array.
Then, once you've finished processing the initial file. Close it, and open up a stream to your new file. Now you can write each string value from the array into the new file.
(* Even better, Use a generic List<String> instead of an array. This will be strongly typed and automatically resize to hold however many lines you need)
Simon
|
|
|
|
|
Simon Stevens wrote: Rather than only holding the line numbers in the array. Make it a string array*, and store the whole line in the array.
What happens when the file is very big (for the sake of argument 1GB)? I already thought about your solution, but it seems to me that it consume a lot of memory if I need to save the whole file into an array. If I want to focus only to copy the lines of interest which I know where they begin and where they end, how do I do it? any way to convert line numbers to file offset and use seek function get there?
|
|
|
|
|
In that case, Have both the read and the write stream open at the same time. Every time you find a line you are interested in from the reader, write it directly to the write stream. This will prevent you from having more than one line in memory at any one time.
Simon
|
|
|
|
|
Is there no way I can use line numbers to get to the specific line and start copying from there forth?
Inbal
|
|
|
|
|
There is no method you can call to just jump to whatever line number in the file. Files do not have line numbers.
You're going to have to read the file, line-by-line, counting the number of lines you read, until you get to the point you want. You don't have to hold onto the lines you don't want in an array. Then start reading the file, line-by-line, and writing those lines out to whatever you want. Even now, you don't have to hold these lines in an array either.
|
|
|
|
|
Hi
Why not writing the line to the new file ?? at the moment you decide to keep this line.
The array is not a very good solution because you need to parse the stream again
in order to go back and forward. (you need to keep the postion of the stream not the line No)
I think a good solution to your problem can be:
1.open the file
2.read line
3.if the line is to be saved -> process the line (if you need)
4.save the line in the output text file
5.read the next line.
|
|
|
|