Reading comma separated values for a CSV file

Hi

Yesterday I was working with some data and found the requirement to work with the CSV files. Al I had to do was read some CSV files. To read the CSV file I had to use Microsoft.Jet.OLEDB.4.0 provider.

I created a function that would take the file path as a parameter and return a dataset containing the table structure of the CSV file. Now the user can do what ever he wants to with this dataset. The function was something like this.

public DataSet getDataSet(string FilePath)

{

            DataSet ds=new DataSet();

            string ConnectionString, CommandText;

Continued...

Using is and as keyword in C# instead of reflection

Hi

Now a days people are so much relayed on the casting reference types and reflection that they forget the use of the other keyword in the system to work out the same. I support the use of the inbuilt keywords like as and is because they are faster and many a times they also make us rely on hard coding the type of the object.

Reflection is a very powerful tool but it also has some performance degradation as against the inbuilt keywords. Also if we use the inbuilt keywords we don’t have to hard code the type in the code. With reflection to check the type of an object we would write the following code.

if(Variable.GetType() == Type.GetType("System.String"))

Continued...

How to not allow user to resize the form

Hi

Many a time in a windows application we don’t want user to move or resize the form. For this reason we have three simple options in the windows form.

First of all we can have Border less forms. To make the form borderless we need to set the FormBorderStyle to none. A borderless form cannot be moved. This option has one drawback that the resulting for will not have any border.

Another method would be to set the ControlBox, MinimizeBox, and MaximizeBox properties to False. We lese have to make the text property of the form to and empty string. This time the form will have a raised border but will not be movable.

And the third and easier way to do this is to make the Size, MaximumSize and MinimumSize property of the form to be same. Now the form can’t be resized because the forms current size is both forms maximum size and minimum size.

Continued...

What is the new policy for deleting the duplicate records in SQL server.
Hi

Sometimes we create table without any primary key and duplicate records are entered in the table. When we have two records in the database with no difference what so ever it’s problematic to distinguish between rows. In these case the other row should be deleted. In SQL Server 2000 we have to use the Rowcount to limit the number of rows affected by the command.

[Note: Remember that the default value is 0, which means that there is no limit of the number of rows returned]

But we can change the value before using the command. We should also remember to change the value back after we are done with the command. To delete 2 rows with same record we need to set the value of Rowcount to 1 and issue a delete command for the record.

Continued...

Working with nullable types in C#

Hi

One of the new features in the C# language is the support for nullable data types. If in your application you are dealing a lot with database having null fields and this will be very helpful although the nullable data types are useful in other situation also.

A data type that can contain defined data type or null value is nullable data type. Defing the nullable type is very simple. All we need to use is the ? modifier.

Normal declaration without nullable type

Double d1=12;

Declaration with nullable type.

Double? D2= 12;

Or

Continued...

Using generic methods into non generic types

Hi

Dot net 2.0 has introduced generics, which is very useful in many situations. We can introduce some generic methods into the non generic types. This brings power of generics to class with requiring the class itself to me parameterized.

To expand on that I will take an example of a simple function Minimum() which accepts to integer Values and returns the minimum of the two.

public int Minimum(int val1, int val2)
{
     return (val2 < val1) ? val1 : val2;
}

Continued...

How to take the asp.net 2.0 application offline when required
Hi

Some time when we want to make major changes to our application or we want to gain the access to the resources that cannot be accessed when the web application is running, we want to take the Application offline.

When we are making some major changes to the web application we do not want the user to use the web application. If the user uses the web application when we are changing the database structure and its related code then it might result in problem.

Some times we might want to take the application offline because we want to access the actively used Access or SQL Server Express database. When an application is actively accessing the database the associated files are locked so that no other process can change them.

Continued...
 
Copyright © 2006 - 2008 Vikram Lakhotia