How to use Sql Profiler?

April 1, 2008

Take some example that some data base updations will be done through one of your screen in the project. To know what are the Sql server tables will be effected when doing some thing in that screen…………………….

Make sure that dabase will be on local machine….

Open Sql Profiler of Sql Server……………….

Go File –> New –> Trace

Then Trace Properties screen will appears and asks to give trace name. Give what ever name you like..

Click Run Button….

Now go for your project screen and click any button which will update or modify database. All the transactions will be loaded in the Trace of sql profiler.

means what are the queries executed when you clicked that button , which stored  procedures executed………etc….

Gives a sample view that what are the tables effected when click a button of a screen in the project.


How to Release Excel Com object From memory after using it?

April 1, 2008

when working with excel work books please use some standard to read data from excel sheet….
1.Create object for Excel Application
2. Create object for Excel Workbooks
3. Create object for ExcelWorkbook
4.Create object for ExcelWorkSheet
when using Excel 2000 component
{
Excel.Application xla = new Excel.Application();
Excel.Workbooks xlwbs = xla.Workbooks;
Excle.Workbook xlwb; Excel.Worksheet xls;
xlwb=xlwbs.Open(“[ExcelFileName]“, 0, false, 5, “”, “”, true, Excel.XlPlatform.xlWindows, “\t”, false, false, 0, true); xls=(Excel.Worksheet)xlwb.Worksheets["ExcleSheetname"];
}
Read necessary data from excel work sheet and after completion of working with
excel then release objects in which manner they are created…
so
{
   ReleaseComObject(xls);
   xlwb.close(false,null,null);
   ReleaseComObject(xlwb);
   xlwbs.Close();
   ReleaseComObject(xlwbs);
   xla.Quit();
   ReleaseComObject(xla);
   Gc.Collect();
}
private void ReleaseComObject(object o)
{
   try
   {
         System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
 }
 catch (Exception ex){  }
 finally {  o = null;}
}


To generate an single quoted string to execute in sql Server

March 31, 2008

if you have more data to check in sql server

like Data1,Data2,Data3…….DataN

the query must be like this

select * from [tablename] where [columnname] in(‘Data1′,’Data2′,’Data3′,…….’DataN’);

then write all the data in a single file each value in one row and save it.like

Data1

Data2

Data3

….

….

….

DataN

save this as one file name.

Then run this program and browse File and click ‘Display’ Button.

Rename the file extension with .jpeg with .execreating-a-file-to-exectue-in-sqlquery-analyzer.jpeg


To get values from one form to another form

March 31, 2008

write this code in second form in which you want to retrieve data from Form1  and assign to required one.

Application.OpenForms["Form1 "].Controls["controlName"].Text


To Fix Grid Header in Asp.net

March 31, 2008

.frozenTop { top:expression(this.offsetParent.scrollTop-2);position:relative;z-index:30; }

write this style in style sheet and for Grid header style class assign this frozenTop.


To get Selected Value from DropDownList in Java script

March 31, 2008

function CheckSelectedItem()
{
var ddllist= window.document.getElementById(“[DropDownListID]“);
var itemName= ddllist.options[ddllist.selectedIndex].value;
alert(itemName);

}


How to convert given decimal value to Degrees?

March 31, 2008

protected string convertToDegrees(decimal decValue)
{
//Method to convert to Decimal values to Degrees.
int Degree = 0, Mins = 0, Secs = 0;
decimal dec_Mins = 0.0M, dec_Secs = 0.0M;
string output = null;

Degree = (int)decValue;
dec_Mins = Math.Abs(decValue – Degree) * 60;
Mins = (int)dec_Mins;
dec_Secs = Math.Abs(dec_Mins – Mins) * 60;
dec_Secs = Math.Round(dec_Secs);
Secs = (int)dec_Secs;

//output = “<td>”+Degree+”</td><td>”+Mins+”</td><td>”+Secs+”</td>”;
output = Degree + “° &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;” + Mins + “‘ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;” + Secs + “\”";
return output;
/* The Logic Used is given below
# The whole units of degrees will remain the same (i.e. in 121.135° longitude, start with 121°).
# Multiply the decimal by 60 (i.e. .135 * 60 = 8.1).
# The whole number becomes the minutes (8′).
# Take the remaining decimal and multiply by 60. (i.e. .1 * 60 = 6).
# The resulting number becomes the seconds (6″). Seconds can remain as a decimal.
# Take your three sets of numbers and put them together, using the symbols for degrees (°), minutes (‘), and seconds (“) (i.e. 121°8′6″ longitude)
*/
}


Sql Helper Class For Executing Queries

March 31, 2008

Please Download File to exectue SqlHelper.cs File sqlhelper_cs.doc


How to Generate Excel File From Grid?

March 31, 2008

protected void BtnDownload_Click()

{

string filename = “[Dowload_Filename]“;  // Give the file name with which it has to download

Response.AddHeader(“content-disposition”,
string.Format(“attachment;filename={0}.xls”, filename);
Response.Charset = “”;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = “application/vnd.ms-excel”;

StringWriter stringWrite = new StringWriter();
//StreamWriter stringWrite = new StreamWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

[GridId].RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());

}

//This method must be included for download a file.

public override void VerifyRenderingInServerForm(Control control)
{

}


How to write functionality for a hyperlink bind in GridView?

March 31, 2008

//in columns of GridView any one is of type Hyperlink assume that in one Column
// When you click on that hyperlink a new window has to open to edit details of
// GridView row
protected void Button1_Click(object sender, EventArgs e)
{
[GridId].DataSource = [Datasource];
[GridId].DataBind();
}

int sno;
protected void [GridId]_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Cells[1].Text = Convert.ToString(++sno); // To Dispaly Serial number in first column

//script is the java script function called after clicking link button in Grid View.
//you can pass parameters to that java script function

script = “javascript:return OpenViewWindow(” + [column value]+ “,” + [column value] + “)”;
// Write OpenViewWindow function in .aspx page script as per requirement

// [HyerLink Control Name] is the name given to control when adding hyperlink control to columns of GridView
((LinkButton)e.Row.Cells[2].FindControl(“[HyerLink Control Name]“)).OnClientClick = script;
}
}
}