|
This is not working in my program, which is weird because it worked in the last one I am making... the difference is that the last one i used SQL database and this new one I am using a Access database... the null probably is still set to DBNull..
foreach (DataGridViewRow d in theTableDataGridView.Rows)
{
if (DBNull.Value == d.Cells[0].Value) ;
else richTextBoxPrintCtrl1.Text += String.Format("{0}\n", d.Cells[0].Value.ToString());
}
it still comes up with an error and the weird thing is, is that the cell is actually not null!
Really I need a better way of doing this, so if you have any ideas please let me know.. what it is suppose to do is go through each row and column, determine if the cell is null (empty), if it is empty then do nothing (skip to next step), if it isn't then print the value of that cell onto a textbox.
|
|
|
|
|
Jacob Dixon wrote: it still comes up with an error
Could you be a bit specific? What is the error message?
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Ew, please change the test so it's easier to read.
if (DBNull.Value <code>!=</code> d.Cells[0].Value)
richTextBoxPrintCtrl1.Text += String.Format("{0}\n", d.Cells[0].Value.ToString());
What error do you get?
|
|
|
|
|
Ok I nested it within a try and catch statement like I did in my last program and it worked!! I used the length that I found instead of DBNull but it works both ways:
<br />
try<br />
{<br />
if (d.Cells[1].Value.ToString().Length >= 1) richTextBoxPrintCtrl1.Text += String.Format("{0}\n", d.Cells[1].Value.ToString());<br />
<br />
if (d.Cells[2].Value.ToString().Length >= 1) richTextBoxPrintCtrl1.Text += String.Format("Birthday: {0)\n", d.Cells[2].Value.ToString());<br />
<br />
<br />
richTextBoxPrintCtrl1.Text += "\n\n";<br />
}<br />
catch (Exception ex)<br />
{<br />
return;<br />
}<br />
<br />
<br />
Can someone explain why this works when I do this? It is working correctly now, so the cells are not empty! But when they are not within a try and catch it doesn't work?
|
|
|
|
|
Jacob Dixon wrote: richTextBoxPrintCtrl1.Text += String.Format("{0}\n", d.Cells[0].Value.ToString());
NullReferenceException was unhandled
Object reference not set to an instance of an object.
|
|
|
|
|
even with the:
if (DBNull.Value != d.Cells[0].Value)richTextBoxPrintCtrl1.Text += String.Format("{0}\n", d.Cells[0].Value.ToString());
it still comes up with the same error
|
|
|
|
|
Having you tried stepping through the code to see where exactly it throws the exception?
I am not a Winforms expert, so I don't know if one row in a grid can have cells and another cannot. Either way, it would be safe to ensure d.Cells has length >= 1 before you access it like that.
Also, rewrite your condition like Piebald says.
Cheers,
Vikram.
"I will put my new found knolage to good use" - Captain See Sharp.
"Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.
|
|
|
|
|
Yes, the last program I wrote I used the code I had and left the if statements empty, which isnt good, but for some reason when I did the DBNull.Value != d.Cells[0].Value it would not work... I couldn't use a != for some reason, I do not remember the error message. I like your idea about the length. That way I could skip using the DBNull, but for programming knowledge, I would like to know why it wasn't working..
|
|
|
|
|
|
The reason it works when you use it with a try catch is because on your catch you just ignore the error. So with this new code, your creating an exception and not handling it.
By the way, you should never have empty catches, or catches with things like return. Just bad coding practice. What you need to do it check what error you are throwing, and where, and we can help you solve the issue.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Well I feel like a idoit. Sorry for wasting your guys times but I figured it out..
It had to do when it reached the birthday column that was causing all the problems. I had it like this:
richtextbox1.Text += String.Format("Birthday: {0)", blah blah);
see the problem? I had a parenthesis instead of a bracket.. I had to look hard to notice it.. maybe I should reduce my resolution lol.. Thanks guys and sorry for all the trouble.
|
|
|
|
|
You're welcome.
A note, though - it is considered rude to delete your posts, especially if somebody has replied to them.
Cheers,
Vikram.
"I will put my new found knolage to good use" - Captain See Sharp.
"Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.
|
|
|
|
|
Sorry I was not aware of that... I was thinking it was rude for all the messages I had taking up almost an entire page lol. Won't do it again, thanks!
|
|
|
|
|
i was trying with WebClient, but it looks like it cant be uploaded in that way or at least i dont know the way, if you know how to upload a file with this, reply this. if you know in any other way reply anyways. i would prefer if it is a short code.
thanks.
modified on Monday, February 04, 2008 7:58:41 AM
|
|
|
|
|
letueros wrote: if you know in any other way reply anyways.
By asking in the right forum[^]
Cheers,
Vikram.
"I will put my new found knolage to good use" - Captain See Sharp.
"Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.
|
|
|
|
|
This is the wrong place to ask that question, but I'm in a magnanimous mood.
Among the vast swath of free and commercial FTP packages, my favorite is this one:
edtFTP.NET[^]
Easy to use, the free package is LGPL and the next upgrade is only $99 and adds great functionality.
It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein
|
|
|
|
|
Please post your programming questions here: http://www.codeproject.com/script/Forums/View.aspx?fid=1649[^]
It is dedicated to C#. The forum you are posting to, is not the right place. It will not be answered in this forum.
What you are doing is like smoking in a No Smoking space right under the sign! Read the text above which describes the lounge.
// "In the end it's a little boy expressing himself." Yanni
while (I_am_alive) { cout<<"I love programming."; }
|
|
|
|
|
1. Remove the case from your computer.
2. Insert into a tub of warm water with plenty or soap suds
3. Scrub the PC until all trace of your code is gone - preferably use a detergent like CrapBegone.
4. Repeat with all other computers that you've come into contact with.
|
|
|
|
|
Hi guys,
I m trying to make a application to send SMS messages. I want to use C# and Sql Server.
Can someone tell me witch SMS Gateway i can use? except Ozek ing !??
Thanx.
|
|
|
|
|
|
I need help with the code for making an mdiform transparent
tony-yeyo
|
|
|
|
|
Try setting the opacity property.
|
|
|
|
|
You asked the same question an hour ago. Don't repost, it's rude. Learn to be patient. Have you tried searching Google?[^] I skimmed the results, and found the solution to the problem. The entire process took 30 seconds.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
Hi everybody.
I have been working on a program that <b>takes a lot of time</b> to solve big mathematical problems
as there would be so many arrays all needs to be inverted and then processed with so many operations to solve some equations...
The question I need to ask is >:
is there any way to reduce the time needed to achieve those math operations ,knowing that we changed the algorithms so may times and nothing changed, >>
<b><<<<<Some of my friends suggested combining this project with some java application and runnig it on a lan to use all PC's connected to it.... ARE THEY LIVING ON MERCURY...huh>>>>>
</b><u></u>
is such thing applicable in our world or what..??
thanks a lot....
|
|
|
|
|
I can't imagine that java would be faster than the C languages... unless someone can correct me on this.
If you are solving huge math problems that you want done fast you'll need an equally fast CPU, just look at some of the most powerful computers on the planet, and that's what they are solely used for - solving math.
Mark.
|
|
|
|