Friday 18 May 2012

Convert a Color Image into Grascale

First create a new C# Windows Form Application, Add two picture boxes and a button. (I am using default names of the controls.) 

Set an image for the first Picture Box (pictureBox1) 

Add the following code to the button click event. 





Bitmap bitmap1 = new Bitmap(pictureBox1.Image); 


int width1 = bitmap1.Width;
int height1 = bitmap1.Height;


Bitmap bitmap2 = new Bitmap(width1, height1);


for (int i = 0; i < width1; i++)


{


    for (int j = 0; j < height1; j++)
    {
Color color1 = bitmap1.GetPixel(i, j);


byte R = color1.R;
byte G = color1.G;
byte B = color1.B;


int common = (R + G + B) / 3;
color1 = Color.FromArgb(common, common, common);
bitmap2.SetPixel(i, j, color1);


    }


}


pictureBox2.Image = bitmap2;

Thursday 17 May 2012

How to use Database CURSOR


cursur

first create a table ...........

create table tbl_cursor
( ID int primary key not null,
name varchar(50) not null,
Gender char(1) not null

)

.....insert the data------
insert into tbl_cursor values (1,'om','M')
insert into tbl_cursor values (2,'ram','M')
insert into tbl_cursor values (3,'alice','F')
insert into tbl_cursor values (4,'grey','F')


select * from tbl_cursor

now create the cursor.......

DECLARE @ID BIGINT, @Gendar NVARCHAR(5)
DECLARE @MyCursor CURSOR
SET @MyCursor = CURSOR FOR (SELECT ID, Gendar FROM tbl_Curser ')
OPEN @MyCursor
FETCH NEXT FROM @MyCursor INTO @ID, @Gendar
WHILE @@FETCH_STATUS = 0
BEGIN
 IF(@Gendar = 'M')
 BEGIN
  UPDATE tbl_Curser SET Gendar = 'F' WHERE ID = @ID
 END
 IF(@Gendar = 'F')
 BEGIN
  UPDATE tbl_Curser SET Gendar = 'M' WHERE ID = @ID
 END
 FETCH NEXT
 FROM @MyCursor INTO @ID, @Gendar
END
CLOSE @MyCursor
DEALLOCATE @MyCursor

How to get First Day date and Last day Date of the current week.


How to get First Day date and Last day Date of the current week.


ans-

declare @start_date DATETIME
SET @start_date=dateadd(week, datediff(week, 0, getdate()), 0) ;

-- Get the last date of the last week

declare @end_date DATETIME
SET @end_date=dateadd(week, datediff(week, 0, getdate()), 6) ;
select 

CONVERT(VARCHAR(10),@start_date,105) 'start day date of the week',
CONVERT(VARCHAR(10),@end_date,105) 'end day date of the week'

CONVERT(VARCHAR(10),@start_date,105) : This is used for removing the time part from the DateTime data type.