Browsing 7239 questions and answers with Jon Skeet

object reference not set to an instance of an object when using parameter

Can someone tell me how i can set the object reference to an instance? .... Here, user_id is the parameter which takes a textbox value into the sql statement. private void...
Jon Skeet
people
quotationmark

EDIT: There are multiple things wrong with your code: You're not specifying the user_id parameter in the command, although it's in the SQL You're trying to use the InsertCommand of the adapter even though you haven't specified any... more 11/12/2013 6:58:24 AM

people

Queue of action delegates not invoking correctly, why?

I was trying to make a Queue<Action>. When I went to dequeue and invoke each action, it kept stopping at 4. I walked through the code and it was processing everything...
Jon Skeet
people
quotationmark

The problem is that the count decreases as you dequeue items. So by the time i is 4, the count is also 4, so the loop stops. If you want to keep dequeuing until the queue is empty, you could use: while (_actionQueue.Count > 0) { ... more 11/11/2013 10:57:59 PM

people

Casting enums in a class

I have five cases of enums that look like this one below: public enum Answers{ A(0), B(1), C(2), D(3), E(4); Answers(int code){ this.code = code; } ...
Jon Skeet
people
quotationmark

You can make your enums implement an interface: public interface Coded { int getCode(); } Then: public enum Answers implements Coded { ... } And: public class Test<T extends Enum & Coded> { public void tester(T... more 11/11/2013 6:16:15 PM

people

What happens if the static class Load fails

Lets say the type static class MyClass fails to load during AppDomain.AssemblyLoad. Maybe the class contains a static property which reads the connection string from the config....
Jon Skeet
people
quotationmark

so will it reload again for further calls on some methods on that class? No. If type initialization fails for a particular type, that type is effectively useless throught the lifecycle of the AppDomain. Any further attempt to use the... more 11/11/2013 4:31:13 PM

people

What's wrong on taking this XML element?

XML: <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:media="http://search.yahoo.com/mrss/"...
Jon Skeet
people
quotationmark

You're using Element("author") and Element("name") as if they're not in a namespace. The namespace will have been defaulted to the same namespace as entry, so you want: var ns = "http://www.w3.org/2005/Atom"; // Just use an implicit... more 11/11/2013 10:25:00 AM

people

Correct way to use periods for daylight saving with the help of Joda Time

I am getting incorrect results because of the daylight savings for that day. I used, Calendar todays =...
Jon Skeet
people
quotationmark

The simplest approach is probably to use something like: public int getHoursInDay(LocalDate date, DateTimeZone zone) { DateTime start = date.toDateTimeAtStartOfDay(zone); DateTime end =... more 11/11/2013 9:26:09 AM

people

Enable an User Authentication in EmbeddedD Derby

I have a program that has a menu with two options first,to create a new database second,open existing database my database creation part code is as follows public...
Jon Skeet
people
quotationmark

From the documentation: When user authentication is enabled (which it is not by default), the user requesting a connection must provide a valid name and password, which Derby verifies against the repository of users defined for the... more 11/11/2013 7:17:57 AM

people

convert a date format yyyy mm dd in sqllite

need a date format like this in sqllite2013-10-29 my query was SELECT strftime('%Y-%m-%d', '29/10/2013') but it showing blank output.I don't know what is the problem. MY ANS...
Jon Skeet
people
quotationmark

According to the documentation, the second argument of strftime is meant to be a timestring, which need to be in one of the following formats: YYYY-MM-DD YYYY-MM-DD HH:MM YYYY-MM-DD HH:MM:SS YYYY-MM-DD HH:MM:SS.SSS ... more 11/11/2013 7:12:28 AM

people

Passing Datetime in SQLCommand

I have to insert a row in my SQL Server via VS 2008 and my codes goes as follows; conn = New SqlConnection conn.ConnectionString = String.Format("Data Source={0};...
Jon Skeet
people
quotationmark

Don't use string.Format to put parameters into your SQL to start with. Instead, use parameterized SQL, and specify the values for those parameters. This will avoid SQL Injection Attacks as well as helping avoid unnecessary and problematic... more 11/11/2013 6:57:25 AM

people

parse decimal from string in any format

Any implementation for the next method: public static decimal StringToDecimal(string sValue) { if (string.IsNullOrEmpty(sValue)) { return 0; } ... } my...
Jon Skeet
people
quotationmark

When you call decimal.TryParse or decimal.Parse, you can specify a culture (and therefore avoid just picking up the system settings). You could try each culture you're interested in one at a time until you find one where the value parses... more 11/11/2013 6:53:20 AM

people