Search This Blog

Wednesday, March 18, 2009

How to select image from database

See the below example to select image from database

System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandText = "SELECT * FROM [REPORT_TABLE]";
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = _connectionString;
cmd.Connection = conn;
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd.CommandText, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow dr = ds.Tables[0].Rows[0];
Byte[] b = (Byte[])dr["IMAGEFIELD"];
MemoryStream ms = new MemoryStream(b);
this.pictureBox1.Image = Image.FromStream(ms);

How To insert Image into database

See below example to insert image into database

string uploadFileName = string.Empty;
byte[] imageBytes = null;
if(imageUpload != null&& imageUpload.HasFile)
{
uploadFileName = imagUpload.FileName;
imageBytes = imageUpload.FileBytes;
}
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = _connectionString;
cmd.CommandText = "INSERT INTO REPORT_TABLE (IMAGEFIELD,IMAGENAME) VALUES (@image,@filename)";
cmd.Parameters.Add("@image", SqlDbType.Image, imageBytes.Length).Value = imageBytes;
cmd.Parameters.Add("@filename", SqlDbType.VarChar, 50).Value = uploadFileName;
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();

Tuesday, March 17, 2009

How To do invisible a column of Gridview

Sometimes we need to do invisible some particular column of a gridview for some cases.This can do as follows.
In below example admin can Only view column 2 and 21.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(user != "Admin")
{
if(e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[2].Visible=false;
e.Row.Cells[21].Visible=false;
}
else if(e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].Visible=false;
e.Row.Cells[21].Visible=false
}
}

}

Monday, March 2, 2009

Page Flashing(Smooth Transform)

Write below line whithin '<'head>'<'/head> tag
'<'meta equiv="Page-Exit" contents="blendtrans(Duration=0.5)">
page will seem flashing for 0.5 second at page loading.

How To Refresh a Web Page

Write below code within '<'head>'<'/head> tag

'<'meta http-equiv="Refresh" content="10" />

Note:  it will Refresh a web page every 10 seconds