Browsing 7239 questions and answers with Jon Skeet

System.Format Exception

The programm i wrote throws up an Exception because of this code: queryString = String.Format("INSERT INTO Playlists (PlaylistID, PlaylistName, PlaylistCreator) VALUES ('{0}',...
Jon Skeet
people
quotationmark

Don't fix the exception - stop constructing SQL like this to start with. (The exception is due to a typo as Pheonyx suggested, but don't just fix that.) Instead, use parameterized SQL, and specify the values as parameter values.... more 2/17/2015 2:40:52 PM

people

Cannot resolve System.Linq namespace

Working in a standard visual studio 2013 web app, I realized that it seems not possible to resolve the System.Linq namespace, e.g. on mylist.Sum(...) in a class when using...
Jon Skeet
people
quotationmark

All the LINQ methods are extension methods. The compiler only knows which extension methods you're interested based on which using directives are present in your code, e.g. // Imports extension methods from all static classes in the //... more 2/17/2015 2:25:14 PM

people

subtracting Dates and saving value in different column of database

Ok, so What i want to do is take Two dates, subtract them and insert their answer (in integers) to another column. Should be like 15 days and so on. The dates to be fetched are...
Jon Skeet
people
quotationmark

These lines: var diff = DateTime.Parse(TextBox2.Text.ToString()).Subtract(DateTime.Parse(TextBox1.Text.ToString())); cmd.Parameters.AddWithValue("@NumOfDays", diff); set the value of the @NumOfDays parameter to a TimeSpan. Firstly,... more 2/17/2015 11:29:55 AM

people

for each loops ; String cannot be converted to int?

I need to acess 2D array and write some information there. I want to use for-each loop for this. Here is my code. But when executing it says ; q13.java:24: error: incompatible...
Jon Skeet
people
quotationmark

It doesn't make sense to use a and b as indexes into an array - they are themselves String[] variables - check the declaration. If you're trying to iterate over every element in the array, I suspect you want: for(String[] a : St) { ... more 2/16/2015 3:30:09 PM

people

How does GetType() knows the type of a derived class?

Why this works: Object o = "my string"; Console.WriteLine(o.GetType()); Output: System.String This would make sense if the function call was dispatched to the String class,...
Jon Skeet
people
quotationmark

The execution-time type is part of the data of the object itself. It's almost like it's a hidden read-only field in System.Object, and GetType() just returns the value of that field. (It's not quite that simple, but that's a reasonable... more 2/16/2015 3:06:24 PM

people

How to run Java Program with class having sub class in different package hierarchy?

I have two classes like: Class GetData is like: package com public class GetData{ private String name = "John"; public String getName(){ return name; } } package...
Jon Skeet
people
quotationmark

The problem is with how you're specifying the classpath. You just need to specify the directory which is at the root of the directory containing the classes, so if you've got com/GetData.class you just need: javac -cp .... more 2/16/2015 2:44:30 PM

people

Optimization ignore function calls

I've created a button which is linked to the following function: private void btnSetVal_Click_1(object sender, RoutedEventArgs e) { //VolumeMeter.Value =...
Jon Skeet
people
quotationmark

The problem is that you're sleeping on the UI thread, which means the UI can't update. Instead, you should use a timer, e.g. a DispatcherTimer to call a method repeatedly (until it's finished). Alternatively, make your method async and... more 2/16/2015 12:41:46 PM

people

Java error in making file through console

I want to make a file though the cmd in java using this code Runtime.getRuntime().exec("mkdir C:\\Users\\Nick\\test"); and i get this annoying error: Exception in...
Jon Skeet
people
quotationmark

mkdir isn't a standalone executable you can launch as a separate process - it's a command that the Windows command shell understands. So you could run cmd.exe /c mkdir ...: Runtime.getRuntime().exec("cmd.exe /c mkdir... more 2/16/2015 9:14:43 AM

people

How do I customize a form based on XML data?

I'm making a simple to-do list and want to store the tasks in an XML file. My XML file looks like this: <Task> <Title>Make a List</Title> ...
Jon Skeet
people
quotationmark

Well, firstly you'd need multiple tasks in your XML file, e.g. <Tasks> <Task> ... </Task> <Task> ... </Task> </Tasks> Then you could iterate over all the tasks like... more 2/15/2015 2:48:37 PM

people

Only base method of generic called

I have the following "models": My base class: public abstract class Search : Model { //Properties ... public void ShallowCopy(Search reference) { ...
Jon Skeet
people
quotationmark

Overload resolution is performed at compile-time, and in JustAMethod it's performed once, not once per type-argument. So primaryModelCopy.ShallowCopy is resolved to the Search.ShallowCopy method. There are two options here: You could... more 2/15/2015 10:43:51 AM

people