Friday, May 27, 2011

How to check from your Vb6 code if your Access database returns an empty string.

Sometimes if you are connecting to an Access DB , you may need to find if some field value is empty and perform some function on the basis of it .You may use the IsNull function to find if the field is empty in the db.

Dim cn As New ADODB.Connection
 cn.CursorLocation = adUseClient
 cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\stduser\Desktop\db1.mdb;Persist Security Info=False"

 Dim sql As New ADODB.Command
 sql.ActiveConnection = cn
 sql.CommandText = "Select City from Table1 where Country=" & "'" & Me.Field1.Text & "'"

 Dim rec As New ADODB.Recordset
 rec.Open sql

 If IsNull(rec.Fields(0).Value) Then
    -------  
Else
   ------------  
 End If

Tuesday, May 3, 2011

Automatic Properties C#

Just use code as following for automatic properties in C#. You do not need to write the  tedious way as earlier.

 public Bitmap GetWaterMark
        {
            get;
            set;
        }

Monday, May 2, 2011

How to make an image transparent.

Sometimes, we are needed to make an image transparent-.to use it as an watermark or something simillar. We need to use code as following to convert an existing image to an transparent one.

public Bitmap createwatermark(string filepath)
        {
            float[][] matrixItems ={
   new float[] {1, 0, 0, 0, 0},
   new float[] {0, 1, 0, 0, 0},
   new float[] {0, 0, 1, 0, 0},
   new float[] {0, 0, 0, 0.3f, 0}, // the fourth value (0.3f) is the alpha value for partial transparency....
   new float[] {0, 0, 0, 0, 1}};
            ColorMatrix colorMatrix = new ColorMatrix(matrixItems);
            ImageAttributes imageAtt = new ImageAttributes();
            imageAtt.SetColorMatrix(
               colorMatrix,
               ColorMatrixFlag.Default,
               ColorAdjustType.Bitmap);
            Bitmap sourceimage = new Bitmap(filepath);
            Bitmap bitmap = new Bitmap(sourceimage.Width, sourceimage.Height);
            Graphics g = Graphics.FromImage(bitmap);

            g.DrawImage(sourceimage, new Rectangle(0, 0, bitmap.Width, bitmap.Height),0.0f,0.0f,sourceimage.Height,sourceimage.Height,GraphicsUnit.Pixel,imageAtt);
            return bitmap;
        }