Specified cast is not valid?

From your comment: this line DateTime Date = reader.GetDateTime(0); was throwing the exception The first column is not a valid DateTime. Most likely, you have multiple columns in your table, and you’re retrieving them all by running this query: Replace it with a query that retrieves only the two columns you’re interested in: Then try … Read more

Escape double quotes in a string

No. Either use verbatim string literals as you have, or escape the ” using backslash. The string has not changed in either case – there is a single escaped ” in it. This is just a way to tell C# that the character is part of the string and not a string terminator.

How to declare session variable in C#?

newSession is a poor name for a Session variable. However, you just have to use the indexer as you’ve already done. If you want to improve readability you could use a property instead which can even be static. Then you can access it on the first page from the second page without an instance of it. page 1 … Read more

The calling thread must be STA, because many UI components require this in WPF

Normally, the entry point method for threads for WPF have the [STAThreadAttribute] set for the ThreadMethod, or have the apartment state set to STA when creating the thread using Thread.SetApartmentState(). However, this can only be set before the thread is started. If you cannot apply this attribute to the entry point of the application of thread you are performing … Read more

How to open a new form from another form

In my opinion the main form should be responsible for opening both child form. Here is some pseudo that explains what I would do: You will just need to create a simple event MoreClick in the first child. The main benefit of this approach is that you can replicate it as needed and you can … Read more

IsNumeric function in c#

I know it’s possible to check whether the value of a text box or variable is numeric using try/catch statements, but IsNumeric is so much simpler. One of my current projects requires recovering values from text boxes. Unfortunately, it is written in C#. I understand that there’s a way to enable the Visual Basic IsNumeric … Read more