|
Scoping issues. Try moving your MSSQL connection before the try - catch block. Also, I've only now noticed it. Just out of curiosity: does your code even compile?
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
I don't think that's it either.
|
|
|
|
|
I dunno.
Does your mark_migrated try to use the same Connection reference that the above code uses? Or does it replace it?
Unrelated to the error:
Please don't keep instantiating and disposing the Connection, Command, and Parameters within the while loop.
0) Instantiate the Connection
1) Instantiate the Command
2) Instantiate and Add the Parmeters
3) while (MSSQLreader.Read())
3.1) Assign the Parameter values
3.2) ExecuteNonQuery
4) Close and Dispose
|
|
|
|
|
In general a bad idea all around.
If an exception occurs you do NOT know why it occurred.
It is possible that almost anything afer that point will cause another exception.
Thus your code should be structured like this.
try
{
...
command.Dispose();
connect.Close();
}
catch(Exception e)
{
try
{
command.Dispose();
}
catch(Exception)
{
}
try
{
connection.Close();
}
catch(Exception)
{
}
}
|
|
|
|
|
Now that it's been pointed out that they are different connections (I completely missed that), I would refactor this. Rather than the pattern you are using here, I would look to use the using command. Also, if you pass in CommandBehavior.CloseConnection on your call to ExecuteDataReader , you will automatically close the ocnnection when you finish iterating over the data reader.
|
|
|
|
|
but how can I use the CommandBehavior.CloseConnection with ExecuteNonQuery()?
|
|
|
|
|
Well, you are using ExecuteReader in your code, not ExecuteNonQuery. ExecuteReader can take CommandBehavior.CloseConnection as a parameter
|
|
|
|
|
I have a standalone HTML page used for data entry by a third party application. The form is opened in an IE window directly from the directory that it is stored. What I need to do is send information from a C# Class Library that is being called by a different system and send the information to this html page. ideas?
basically I want to do something like have javascript poll a tcp port until I send something but not sure how that works.
Also considered writing a C# COM object and using the object tag to make that part of the page and do all communication through C# but not sure if this is the best route.
|
|
|
|
|
How about ASP.NET? Seems to me it was created for this kind of stuff.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
A non C# solution - you might want to try and use Comet notifications[^].
|
|
|
|
|
Hi all, I am trying to create a method that allows users to convert a Word document to other kinds of files like PDFs, text files, etc., and that means using Word library and Word components. These need the Office Interop Word Assembly to work and I heard that hosting companies won't install it for you because of the licensing fee and they won't let you install it on their web server unless you sign up for a dedicated server. Are there open source alternatives out there that I can use? Thanks in advance.
modified 17-Sep-12 11:17am.
|
|
|
|
|
Yes, you can use the OpenOffice API for .NET to manipulate Office docs programmatically. I've used it before, and it works.
However, if you do decide to use it, be warned: it's not easy, and it's very poorly documented, not to mention intuitive. But if you do get it working, it's a wonder.
Good luck!
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
Sounds like something that would be well worth reading as an article.
|
|
|
|
|
I would actually post it, if I'd remember how to do it. I may be able to dig the source though. Nice idea though, I was actually thinking about an article on automating some stuff, although not Office files. Thanks for the idea!
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
Hello friends
I am practicing C# by solving the Problems in projecteuler.net. Now I am working on 20th one.
I create a project and here it is my code:
const int number = 100;
double fact = Library.Math.Fact(number);
BigInteger bigInteger = new BigInteger(fact);
int sum = 0;
while (bigInteger > 0)
{
sum += (int)(bigInteger % 10);
bigInteger /= 10;
}
Console.WriteLine("Sum of the digits int the number {0}! is {1}", number, sum);
static double Fact(int number)
{
return number == 1 ? 1 : number * Fact(number - 1);
}
It is absolutely fine, isn't it?
I have tried the small number that I can calculate manually and the result given was correct. But when I give to the site the rsult of my code it doesn't accept the answer.
What's wrong with my code?
modified 18-Sep-12 9:40am.
|
|
|
|
|
Meysam Tolouee wrote: It is absolutely fine, isn't it?
Depends on how you define "fine".
Well first, your recursive alogorithms could be an iterative one, that would be even finer.
Next: for large number you round, because the precision of double may be not good enough. So there are rounding error for large numbers.
By the way, I didn't downvote you and I wonder why someone did.
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
I just changed the output of method Fact() from double to BigInteger.
Now it really works fine.
Fine means it gives me true result.
|
|
|
|
|
Meysam Tolouee wrote: Now it really works fine.
Fine means it gives me true result.
Ok, if it's fine for you, it's fine for me, too
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
ihoecken wrote: By the way, I didn't downvote you and I wonder why someone did.
I've just counter-voted, but I have a suspicion as to why he was univoted.
|
|
|
|
|
I'd disapprove it because it uses recursion where none is necessary. But that's just me.
|
|
|
|
|
Well, that's the effect of how we're taught recursion in schools and colleges - using examples where recursion is unnecessary (e.g. finding the factorial of a number).
|
|
|
|
|
I know. I know.
And were I teaching it I'd have to do the same, but I'd then show the iterative alternative.
"Recursion is a very powerful programming technique that is best avoided whenever possible."
|
|
|
|
|
I still it funny that when recursion is taught in school they may just touch on the the effect this has on the stack, or even what the stack is!
Then all the noobs are scratching their heads when they see "Stack Overflow" errors.
|
|
|
|
|
if you are trying to determine the number of digits, this will not work;
sum += (int)(bigInteger % 10);
What you need is:
sum++;
What you had was the sum of the digits, not the number of digits. I cannot understand why somebody wants the sum of digits, really does not tell you anything usefull. The number of digits does.
|
|
|
|
|
Actually I didn't want to count the digits. I wanted to sum the digits and I did.
As I said that website is full of Problems that their purpose is practicing.
They doesn't need to make sense.
|
|
|
|