10,796 questions
1866
votes
26
answers
2.5m
views
What is a NullReferenceException, and how do I fix it?
I have some code and when it executes, it throws a NullReferenceException, saying:
Object reference not set to an instance of an object.
What does this mean, and what can I do to fix this error?
103
votes
6
answers
113k
views
How do I create a parameterized SQL query? Why Should I?
I've heard that "everyone" is using parameterized SQL queries to protect against SQL injection attacks without having to vailidate every piece of user input.
How do you do this? Do you get this ...
58
votes
3
answers
55k
views
What do Option Strict and Option Explicit do?
I saw this post:
Typos… Just use option strict and explicit please.. during one software development project, which I was on as a consultant, they were getting ridiculous amounts of errors ...
140
votes
28
answers
248k
views
How to get ALL child controls of a Windows Forms form of a specific type (Button/Textbox)?
I need to get all controls on a form that are of type x. I'm pretty sure I saw that code once in the past that used something like this:
dim ctrls() as Control
ctrls = Me.Controls(GetType(TextBox))
I ...
426
votes
26
answers
119k
views
What is the best workaround for the WCF client `using` block issue?
I like instantiating my WCF service clients within a using block as it's pretty much the standard way to use resources that implement IDisposable:
using (var client = new SomeWCFServiceClient())
{
...
110
votes
15
answers
331k
views
Download Excel file via AJAX MVC
I have a large(ish) form in MVC.
I need to be able to generate an excel file containing data from a subset of that form.
The tricky bit is that this shouldn't affect the rest of the form and so I ...
258
votes
8
answers
630k
views
HTML encoding issues - "Â" character showing up instead of " "
I've got a legacy app just starting to misbehave, for whatever reason I'm not sure. It generates a bunch of HTML that gets turned into PDF reports by ActivePDF.
The process works like this:
Pull an ...
235
votes
8
answers
416k
views
How do I convert Word files to PDF programmatically? [closed]
I have found several open-source/freeware programs that allow you to convert .doc files to .pdf files, but they're all of the application/printer driver variety, with no SDK attached.
I have found ...
488
votes
20
answers
217k
views
Why is there no ForEach extension method on IEnumerable?
Inspired by another question asking about the missing Zip function:
Why is there no ForEach extension method on the IEnumerable interface? Or anywhere? The only class that gets a ForEach method is ...
197
votes
16
answers
120k
views
Setting Objects to Null/Nothing after use in .NET
Should you set all the objects to null (Nothing in VB.NET) once you have finished with them?
I understand that in .NET it is essential to dispose of any instances of objects that implement the ...
476
votes
16
answers
318k
views
When should I use a List vs a LinkedList
When is it better to use a List vs a LinkedList?
18
votes
11
answers
63k
views
Application not quitting after calling quit
I have a small problem that I can't seem to figure out. I am saving a DataGridView (it's contents) to an xls file. I have no problem in doing so except in my task manager its still showing up that it'...
226
votes
25
answers
231k
views
Get the generated SQL statement from a SqlCommand object?
I have the following code:
Using cmd As SqlCommand = Connection.CreateCommand
cmd.CommandText = "UPDATE someTable SET Value = @Value"
cmd.CommandText &= " WHERE Id = @Id"
cmd....
0
votes
2
answers
1k
views
Send data within Child Forms
I have 3 Forms namely MainForm, Form1 and Form2. MainForm hosts Form1 in a Panel. On Clicking a button in MainForm, I am opening Form2 using ShowDialog() method. Now I have a treeview in Form2. Now I ...
120
votes
20
answers
428k
views
How to solve COM Exception Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))?
When I try to create a instance of a COM class it throws an exception as
Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
Please suggest how could i solve it?
56
votes
3
answers
17k
views
Why is it bad to use an iteration variable in a lambda expression
I was just writing some quick code and noticed this complier error
Using the iteration variable in a lambda expression may have unexpected results.
Instead, create a local variable within the ...
59
votes
2
answers
37k
views
How do you bind a CollectionContainer to a collection in a view model?
I have a view model with a property that exposes a collection of things.
I have a ComboBox whose ItemsSource property is bound to this collection.
Now the user can select from the list.
I want to ...
2
votes
2
answers
13k
views
How can I run code in a background thread and still access the UI?
I made a file search program in visual studio on windows 10 using .net lang,
My problem starts from form1 with a "dim frm2 as form2 = new form2" call,
after the new form being shown i start a while ...
82
votes
8
answers
69k
views
VB.NET equivalent for C# 'dynamic' with Option Strict On
Is there an equivalent for the C# 4 'dynamic' keyword when using type safe VB.NET, i.e. with Option Strict On?
176
votes
8
answers
166k
views
How to loop through all the properties of a class?
I have a class.
Public Class Foo
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
...
150
votes
11
answers
133k
views
Case insensitive string compare in LINQ-to-SQL
I've read that it's unwise to use ToUpper and ToLower to perform case-insensitive string comparisons, but I see no alternative when it comes to LINQ-to-SQL. The ignoreCase and CompareOptions arguments ...
77
votes
24
answers
49k
views
Use float or decimal for accounting application dollar amount?
We are rewriting our legacy accounting system in VB.NET and SQL Server. We brought in a new team of .NET/ SQL Programmers to do the rewrite. Most of the system is already completed with the dollar ...
93
votes
9
answers
96k
views
Way to have String.Replace only hit "whole words"
I need a way to have this:
"test, and test but not testing. But yes to test".Replace("test", "text")
return this:
"text, and text but not testing. But yes to text"
Basically I want to replace ...
45
votes
12
answers
308k
views
Best /Fastest way to read an Excel Sheet into a DataTable?
I'm hoping someone here can point me in the right direction - I'm trying to create a fairly robust utility program to read the data from an Excel sheet (may be .xls OR .xlsx) into a DataTable as ...
182
votes
12
answers
282k
views
What is the C# version of VB.NET's InputBox?
What is the C# version of VB.NET's InputBox?