Current area: HOME -> Blogs -> .NET

Blog Posts Tagged With .NET

Very Quick Guide To DLinq: Part 3 (LIKE, IN, DATEDIFF)
Posted on Wednesday, April 30, 2008 at 6:50 AM
Much of the time, it's fairly straightforward to express an SQL query in Linq instead. However, there are some things that aren't quite so clear how to do. In this article, I'll take a look at some of those.

LIKE

There are a couple of ways to replace LIKE. If you just want to directly use LIKE, then you can do so using the SqlMethods class. To use this, you must add the following using declaration at the top of the file:
using System.Data.Linq.SqlClient;
Then we can use it like this:
var Result = from Book in DB.BookResources
             where SqlMethods.Like(Book.Title, "%java%")
             select Book;
This will create an SQL query that locates all books containing "java" (case-insensitively). Interestingly, you can also do the following:
var Result = from Book in DB.BookResources
             where Book.Title.Contains("java")
             select Book;


Read More
Tags: .NET, C#, DLinq

When Linq and ref Parameters Meet
Posted on Tuesday, April 01, 2008 at 7:17 AM
It's fair to say that I'm a pretty heavy user of Linq. You'll find uses of it scattered across my code, from the obvious (using DLinq to query a database) to the slightly more exotic (writing queries over collections obtained from classes in System.Reflection). Linq often allows you to express a problem very neatly, resulting in compact, readable code. It also factors out the application of operations and leaves you to worry about the operations themselves, likely decreasing bugs.

Fixing A Bug

Today I ran across some code that took a parameter, then used it in a Linq query. Omitting the clutter, it looked something like this:
public void Lookup(string URL, ref int ID, ref int Status)
{
    // ...stuff...
    var Result = from D in DB.Datas
                 where D.URL == URL
                 select D;
    // ...more stuff...
}


Read More
Tags: .NET, C# 3.0, Linq

Very Quick Guide To DLinq: Part 2
Posted on Tuesday, March 25, 2008 at 2:45 AM
In this part I'm going to take a look at inserts, updates and deletes using DLinq.

The Overall Model

First, to make changes to a database, you instantiate the data context object, just as we did before doing selections in the previous part.
var DB = new ResourcesDB();
You then do the required changes; we'll look at this part in just a moment. However, the inserts, updates and deletions are not performed immediately. They do not take place until you explicitly submit the changes:
DB.SubmitChanges();
This means that you can make many changes, then send them to the database all at once.

Inserting Data Into A Table

To make a single new entry to a database table, use the InsertOnSubmit method on the Table object. This takes a single parameter: an instance of the object that represents a row in the the table. You can use the object initializer syntax to write this very neatly.
DB.BookResources.InsertOnSubmit(new BookResource()
{
Read More
Tags: .NET, C#, DLinq

Very Quick Guide To DLinq: Part 1
Posted on Friday, March 14, 2008 at 9:10 AM
We have already written about using Linq, but didn't cover DLinq. This post takes a quick look at getting started with DLinq, which allows you to write Linq queries against databases. Once you're up to speed, you can take a database and be writing Linq queries against it in under five minutes!

In future parts in this series of posts, we'll look at doing database updates, writing more complex queries and debugging. In this one, we'll just look at doing some simple queries.

Creating The Linq to SQL Classes

The bad news is that before you can use DLinq, you have to create Linq to SQL classes to represent your database tables. The good news is that Visual Studio 2008 (aside from the Express Edition) can do all of the hard work for you in this.

Read More
Tags: .NET, C#, DLinq

Float, Double and Decimal: do you know the differences?
Posted on Tuesday, March 11, 2008 at 3:17 AM
There are a number of data types available in the .Net framework for storing numbers with fractional parts. They are each appropriate for different situations, and using the wrong one can lead to errors in calculations.

Thinking About Accuracy

In some applications, you require that calculations involving numbers with fractional parts are exact. Examples of this are in financial applications, where losing the odd cent here and there in a calculation is unacceptable. Customers expect their accounts to be completely accurate, not to mention the tax man.

In other applications, you don't care about exact results, but you are interested in having an answer that is correct to a certain number of significant digits. This is the case in experimental physics, for example. When you make a measurement of something, you can only measure it as accurately as your equipment will allow you. Therefore, you have an inherent error in that value already, which is going to cascade through any calculations you do with it. This means that while your computed answer may be 5.1826, you may know that the values this answer was calculated from were only accurate to three significant digits, and so the last two digits in this result (the 0.0026) don't matter. If there is a computational error in them, so be it - it's not going to hurt us.

Read More

Do try...catch blocks hurt runtime performance?
Posted on Tuesday, February 19, 2008 at 6:23 AM
Recently, a friend mentioned that someone had told him that writing a try...catch block in C# (or substitute some other .Net language here) resulted in a "huge penalty" in terms of performance compared to if you had not written it. That is, merely writing such a block actually hurt program performance, even if an exception was never thrown. He didn't believe this was true, and rightly so - it's completely wrong. This post is a tidied up version of my explanation.

Inside a .Net Assembly

A .Net assembly, if we ignore various headers, consists of three things:
  • Bytecode: a sequence of low-level instructions that specify the body of a method
  • Metadata: a set of tables, a little bit like a database, describing higher level constructs such as classes, methods, signatures and so forth
  • Heaps: places where string constants and other such things are stored
Read More
Tags: .NET, C#, CLR, Exception

C#.NET or VB.NET?
Posted on Monday, February 11, 2008 at 9:10 AM
We get a lot of emails from Programmer's Heaven users. Amongst the requests that we do people's homework, which we ignore, we also get some more interesting questions sent to us too. We figured that when we do, we may as well share our answers more widely, and also this gives other folks a chance to give their input too. Recently we got one from someone who had discovered us through the C# School e-book and asked, "please kindly advise which of the two, C# and VB .NET is better for developing commercial applications like Payroll".

The Similarities

Both languages run in the Common Language Runtime and allow you to have full access to the .Net Class Library. This means that pretty much whatever is in the .Net Class Library is equally available to both VB.NET and C#.NET. Both languages have a similar feature set too, providing strong support for Object Oriented Programming, which is good for developing database-backed applications, as your Payroll surely will be.

Read More
Tags: .NET, C#, VB.NET

Running C# .NET Applications On Fedora 8 Linux
Posted on Sunday, December 09, 2007 at 7:21 PM
One of the main challenges and the reason most corporations choose to target a windows operating system for their custom applications is that developing custom linux applications is not something that most entry level developers know how to do. To acomplish this they would have to rely on some of the most unreliable groups of programmers to control in the business: The Linux GUI or Java GUI Developers, both of which are hard to find, and even harder to manage. Some have even been known to walk off of jobs just because they weren't given enough of a say on how their master pieces should run and function!

Read More
Tags: .NET, C#, Linux, Mono

Learn C# 3.0 With Our New Series!
Posted on Wednesday, November 21, 2007 at 9:31 AM
This week we are starting a brand new four part series, covering the new features of C# 3.0! The first article of the series covers type inference. You'll learn:
  • What is type inference anyway?
  • How can you take advantage of it?
  • What does the new "var" keyword do?
  • Is this at all related to Variant types in Visual Basic?
  • Will using this hurt the performance of your programs at runtime?
Check out the article!
Tags: .NET, C#, C# 3.0, types

Visual Studio 2008 .Net Goes Gold!
Posted on Wednesday, November 21, 2007 at 4:35 AM
The Microsoft Visual Studio .Net development team have released Visual Studio 2008 to manufacturing. That means it will be in our hands Real Soon Now. For those of us who have been eagerly awaiting the advances made in this new version of Visual Studio .Net, this is exciting news.

First of all, there are significant language updates. Both C# and VB.NET have new language features that will increase developer performance, allow more opportunities for abstraction and code re-use and help us to write more readable code.

Linq is one of the big new features. It integrates a query language into C# and Visual Basic, allowing for writing of declarative, SQL-like queries directly into programs. These can be type-checked at compile time, unlike strings of SQL. Furthermore, this is not just for databases: you can run queries over collections of objects, XML documents and more. For databases there's another win - because you are writing in C# or VB syntax, you don't need to worry about the syntax of SQL, or which database server you are using.

Read More

Vertical Label Control
Posted on Monday, November 12, 2007 at 3:30 AM
I have published an article regarding vertical label control at the Code Project website. Kindly go to http://www.codeproject.com/useritems/Vertical_Label_Control.asp to check it out.

Subscribe

RSS Feed RSS Feed

More Tags

.NET C C# C# 3.0 C++ Embedded engineering service eveh3d firmware Hardware Linux Made-In-China offshore Operating System Outsource Perl product development Programming R&D Software

Help

Check out the Blog FAQ.




Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.