Search This Blog

Wednesday, May 6, 2009

How To execute a query string above 8000 chars

You can execute a query string above 8000 chars as follows:

Declare @queryString1 varchar(8000)
Declare @Condition1 varchar(8000)
set @queryString1 =' ..any query string ... '
set @condition1=' ...any query condition....'

exec ('select [column]...... from Table_Name ......... '+ @queryString1 + @condition1)

Friday, April 24, 2009

Print Crystal Report(Server-Side)

crReportDocument.PrintOptions.PrinterName= printername;
// set 0 for all documents to print
crReportDocument.PrintToPrinter(1,false,0,0);

where crReportDocument is an object of ReportDocument and printername is the name of the printer.

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