Installing Intel X3100 Graphics Driver on Toshiba Sattellite M200 Laptops having WS2003 as Operating Sytem

September 29, 2008 at 12:03 pm (DevSoft Tweaks)

 

Those of you who are having trouble in installing X3100 Graphics Driver on Toshiba Satellite M200 and similar laptops in that series, the problem is that the driver that toshiba people have on their site is old version and it works only on Windows XPSP2 and later OS,it does not work on Windows Server 2003 OS.

So the solution is just download the Graphics Driver for Windows XP for Dell Inspiron 1525.

These dell people have latest  driver and it install very smoothly on Windows Server 2003.

If this also is not working for you than you can add setup.exe in the application verifier and do the proceeding as given in this post.

http://smallworkarounds.blogspot.com/2008/09/installing-photoshop-cs3-on-windows.html

Permalink Leave a Comment

When to use using and when to use try catch to do the cleaning

September 29, 2008 at 12:03 pm (C#)

  1. We have two ways to clean up utilized resources in C# either we can use try..catch..finally statements series or we can use the using statement in C#
  2. The thing is that resources should be released and cleanup must be performed either before exitting the using block or just entering up the finally block.
  3. Use using Statement in C# to release up the resources when the creating type implements the IDisposable interface.
  4. Use try..catch..finally when we need to perform cleanup but not necessarily employ the Dispose Method.

Permalink Leave a Comment

Anonymous Types in C#

September 29, 2008 at 8:48 am (C#, Linq)

  1. Anonymous types in C# are a new concept which shipped with .net framework 3.5
  2. Anonymous types are nothing but it simply states that we dont have to define a type and that type is defined automatically by C# analysing the right hand side.
  3. Anonymous Types are very important in the LINQ word.
  4. Keyword var is used to declare an anonymous type.
  5. They are immutable and thus dont require any property getter or setter methods
  6. They must always be initialized so that the compiler can build the type defination and bind the anonymous type with that , and it is only possible only when we have any thing in the right hand side of an anonymous type thus anonymous types should always be initialized.

//1.Shows Simple anonymous varible declarations and iterating using for loop
var fabonici = new int[]{1,1,2,3,5,8,13,21};
for( var i = 0; i<fabonici.Length; i++)
{
    Console.WriteLine(fabonici[i]);
}

//2.Show Simple anonymous variable declarations and iterating using foreach loop
var fabonici =  new int[]{1,1,2,3,5,8,13,21};
foreach (var fibo in fabonici)
Console.WriteLine(fibo);

//3.Linq query used as iterand in foreach statement.
var fabonici = new int[]{1,1,2,3,5,8,13,21};
foreach (var fibo in
         from f in fabonici
         where f%3 == 0
         select f)
Console.WriteLine(fibo);

Permalink Leave a Comment

Custom functions recieving StoredProcedure Name and Command Parameters to reduce code duplicacy, by redundant open() and close() sql Connection calls.

September 29, 2008 at 8:34 am (C#, SqlServer)

 

Here is the sample code for 3 static functions to be written in your SqlHelper or DAL or any other Data Related class.

public static void DBExecuteNonQuery(string storedProcedure,SqlCommand command)
   {       
       using(SqlConnection connection = new SqlConnection(ConnectionString))
       {
           connection.Open();
           command.CommandText = storedProcedure;
           command.Connection = connection;
           command.CommandType = CommandType.StoredProcedure;          
           command.ExecuteNonQuery();
       }
   }

 

1.DBExecuteNonQuery is receiving two parameters one is the name of the stored procedure and other is the prebuild  command having all the parameter names and values, later in the function we open the connection and provide the CommandText as the recieved stored Procedure name, command connection as connection,command type as commandtype.storedprocedure and then we execute the command.ExeuteNonQuery statement.

2.Similarly we do things in other functions the only difference is of the return type and the execute function.

   public static Int32 DBExecuteScalar(string storedProcedure, SqlCommand command)
   {
       Int32 value = 0;
       using (SqlConnection connection = new SqlConnection(ConnectionString))
       {
           connection.Open();
           command.CommandText = storedProcedure;
           command.Connection = connection;
           command.CommandType = CommandType.StoredProcedure;
           value = (Int32)command.ExecuteScalar();
       }
       return value;
   }

3.DBExecuteScalar takes the same arguments but returns an Int32 type value and Executes the stored procedure using command.ExecuteScalar() function

 
   public static DataSet DBExecuteReader(string storedProcedure, SqlCommand command)
   {
       SqlDataReader reader = null;
       using (SqlConnection connection = new SqlConnection(ConnectionString))
       {
           connection.Open();
           command.CommandText = storedProcedure;
           command.Connection = connection;
           command.CommandType = CommandType.StoredProcedure;
           reader = command.ExecuteReader();  

//Here we can write any custom code to convert the reader to a dataset because when the     connection will be closed if we return reader it will complain as it is connected type.

       }
      return dataSet;
   }

4.DBExecuteReader also takes similar arguments but return a SqlReader which you can iterate through to get the desired output.

5.These functions might come handy when you are using multiple opening and closing connection calls it might not help in performance but it make the code look clean and reduce the duplicacy.

6.ConnectionString used above is a static property in the SqlHelper Class which can be used to retreive the connection string from web.config in web applications and app.config in Winforms applications.

public static string ConnectionString

{

get{return System.Configuration.ConfiguraitonManager.ConnectionStrings["connectionsstringname"].ConnectionString;}

}

7.Now we can directly use these functions as following code snippet shows:-

SqlCommand command = new SqlCommand();
        command.Parameters.Add("@firstName", SqlDbType.VarChar).Value = person.FirstName;
        command.Parameters.Add("@middleName", SqlDbType.VarChar).Value = person.MiddleName;
        command.Parameters.Add("@lastName", SqlDbType.VarChar).Value = person.LastName;
        command.Parameters.Add("@gender", SqlDbType.Bit).Value = person.Gender;
        command.Parameters.Add("@email", SqlDbType.VarChar).Value = person.Email;
        command.Parameters.Add("@address", SqlDbType.VarChar).Value = person.Address;
        command.Parameters.Add("@qualification", SqlDbType.VarChar).Value = person.Qualification;
        command.Parameters.Add("@password", SqlDbType.VarChar).Value = person.Password;

        SqlHelper.DBExecuteNonQuery("usp_InsertPerson", command);       

If you want more modularity and donot want to pass command from your business logic  layer and want to make this command only in your Data Access Layer than you can add the following methods to your SqlHelper.cs file

public static DataSet ConvertToSqlCommand(string storedProcedure,SortedList values)

        {

            SqlCommand command = new SqlCommand();

            foreach (KeyValuePair  value in values)

            {

                Type type = value.Value.GetType();

                SqlDbType sqlDBType = ConverToSqlDBType(type);

                command.Parameters.Add(value.Key, sqlDBType).Value = value.Value;

                //SqlDbType value.Value.GetType()

            }

            DataSet dataSet = DBExecuteReader(storedProcedure, command);

            return dataSet;           

        }

        public static void ConvertToSqlCommandForNonQuery(string storedProcedure, SortedList values)

        {

            SqlCommand command = new SqlCommand();

            foreach (KeyValuePair value in values)

            {

                Type type = value.Value.GetType();

                SqlDbType sqlDBType = ConverToSqlDBType(type);

                command.Parameters.Add(value.Key, sqlDBType).Value = value.Value;

            }

            DBExecuteNonQuery(storedProcedure, command);

        }

These two overloaded methods take storedprocedure name and sortedlist ie key value pair as parameters and convert them to sqlcommands and execute the related DBExecute……() function and return the output.

The problem with this approach is that we have to convert System.Type to System.Data.Type ie SqlDBType which is an enumeration thus a probable limitation is that it cannot understand which string is to be converted to char,varchar and nvarchar for rest it works fine.Given below is the method which achieves this you can add another entries if you want.

        public static SqlDbType ConverToSqlDBType(Type systemType)

        {

            if (systemType.Name == "Int32")

                return SqlDbType.Int;

            else if (systemType.Name == "String")

                return SqlDbType.VarChar;

            else if (systemType.Name == "DateTime")

                return SqlDbType.DateTime;

            else

                return SqlDbType.VarChar;

        }

Uploaded Below is the SqlHelper.cs file which achieves the desired result.
http://cid-d3498dea37dde9b0.skydrive.live.com/self.aspx/Files/SqlHelper.cs

Permalink Leave a Comment