Wednesday, December 29, 2010

LINQ to SQL DataContext is not accessable, does not show even in intellisense

I have been seeing this strange behavior using LINQ to SQL in Visual Studio 2008 in the last two months.

I was working on a project and defined my DataContext using the LINQ designer. I applied the same namespace as my main class, yet in my main class I do not see my data context, and when I try to type it, it states it does not exist. I check the backend code of the LINQ designer and everything looks right, same namespace and the DataContext is named properly.

I played around trying many things to no avail, so as a last ditch effort I reinstalled Visual Studio 2008 SP1.

When I went back into Visual Studio 2008 I tried to type out my DataContext variable and still same issue, it wasn't accessable. So I then deleted my LINQ to SQL class.

I now recreate my LINQ to SQL class. Add my stored procedures, save the DataContext and then back to my class and guess what, it is there.

So, now here I am, different machine, a month later, same exact issue on a ASP.NET Web Application in Visual Studio 2008. It would not see my Data Context. So I repeat the steps that fixed it for me before in the follow order:

#1 Reinstalled Visual Studio 2008 SP1 (Yes, on both machines I had already installed Visual Studio 2008 SP1)

#2 Open project back up and delete the Linq To SQL class

#3 Recreate the LINQ to SQL class in the designer

#4 Save and Recompile

That was it, it is now working as expected on this machine also, very strange, hope this helps someone else. The other project type was a ASP.NET Web Service.

Tuesday, December 28, 2010

How to read Excel file in .Net C# and VB.NET

I have many times int the past been asked to import/export data from an excel spreadsheet. In the past I have used Interop and OLEDB, but I found this to be a simple dll which allowed me to roll this stuff out a bit faster. This a very simple, lightweight DLL which allows you to read from an excel spreadsheet without Interop and installing an obsolete OLEDB dll.

Excel Data Reader - Read Excel files in .NET

Lightweight and fast library written in C# for reading Microsoft Excel files ('97-2007).
- Windows with .Net Framework 2
- Windows Mobile with Compact Framework
- Linux, OS X, BSD with Mono 2+