How to measure performance of Queries?

1 SET LANGUAGE ENGLISH
2 SET STATISTICS TIME ON
3 SET STATISTICS IO ON
4
5
6 PRINT 'Result of first Query'
7 Your first Query
8 PRINT 'Result of second Query'
9 Your second Query


Reference

How to reset auto increment value of a table in Ms SQL?

DBCC CHECKIDENT (tablename, RESEED, 0)

How to handle ASP.NET textbox client side events?

function(s, e)
{

alert(s.GetValue());

anotherTextBoxClientİnstanceName.SetValue('asdsd');

}

What is JSP (Java Server Pages)?

JSP - Java server pages.

JSP is programming language(environment) to develop dynamic web pages.
  • Developed by Sun Microsystems
  • Works on both IIS (Internet Information System) and Apache (Commonly Tomcat used)
  • .jsp files are compiled into Java Servlets by a JSP compiler on JSP Servlet engine.
  • .jsp files are parsed once and used forever.
  • <%! ... %> is used for variable and method declarations.
  • scriptlet: <% ... %> tags, any valid Java code is called scriptlet.
  • <% -- my comment -- %> or <% /* my Comment */%>
  • <%= expression ... %> - we do not use (;) at this
  • <%@ directives ... %> : directives give special information about the page to the JSP engine.
  • JSTL - JSP Standard tag library
Advantages:
  • Multiplatform
  • Component reuse by using Javabeans + EJB
  • advantages of Java

Execution steps of .jsp files

  • send .jsp file to JSP Servlet engine
  • parse .jsp file
  • generate servlet source code
  • compile servlet source code into class
  • instantiate servlate
  • send HTML (servlet output) to client
reference

How to manage PHPbb forum databse tables?

How to clean bots from PHPbb forum?

Statistics shown in frontpage such as

Username of last user, total number of users, topics and posts are stored in
  • phpbb_config

  • Last post author name wrote on a forum is stored in
  • phpbb_forums
  • How to change date format at SQL Server?

    How to change date format at MS SQL Server?

    SET DATEFORMAT DMY


    Note: DMY means Day-Month-Year, so you can use MDY or YDM, etc...

    SQL Server stored procedure parameters decrease performance

    When we use parametrs directly in query's WHERE parts,
    performance of query decrease dramatically.

    So we can use local values to copy these parametrs.

    1 ALTER PROCEDURE [dbo].[CalculateSomething]
    2 @myID INT
    3 AS
    4 BEGIN
    5 DECLARE @myIDLocal INT
    6
    7 SET @myIDLocal = @myID -- If you this performance of query
    8 -- will inctrease!
    9 SELECT * FROM myTable WHERE ID = @myIDLocal

    How to use Crystal reports?

    How to connect to Crystal report?
    How to use stored procedures at Crystal reports?
    How to pass parameter to Crystal report?

    1
    2 ReportDocument reportDocument = new ReportDocument();
    3 ParameterField paramField = new ParameterField();
    4 ParameterFields paramFields = new ParameterFields();
    5 ParameterDiscreteValue paramDiscreteValue =
    new
    ParameterDiscreteValue();
    6
    7 /***********************************/
    8
    9 paramField.Name = "@ID";
    10 paramDiscreteValue.Value = textBox.Text;
    11 paramField.CurrentValues.Add(paramDiscreteValue);
    12 paramFields.Add(paramField);
    13 CrystalReportViewer.ParameterFieldInfo = paramFields;
    14
    15 reportDocument.Load(Server.MapPath("Report.rpt"));
    16 CrystalReportViewer1.ReportSource = reportDocument;
    17 reportDocument.SetDatabaseLogon("myUsername", "myPassword",
    18 "192.187.1.1", "myDatabase");

    Reference

    How to get set session variables in ASP?

    How to get set session variables in ASP.NET?
    How to get set session variables in ASP (c#)?
    How to get set session variables at ASP?

    1 //Get session value:
    2
    3 int sessionValue = ((int)Context.Session.Contents["myValue"]);
    4
    5
    6 //Set session value:
    7
    8 Context.Session.Add("mySessionValue", 1001);

    How to access connection string from code?

    How to call connection string at ASP.NET (C#)?
    How to call connection string in ASP?

    1 ConfigurationManager.ConnectionStrings["MyConnectionString"]
    .ConnectionString

    How to create excel at ASP?

    How to create excel at ASP.NET?
    How to make excel file at ASP web Page?

    In the example belove we open a template Excel file, change it content
    and save it as an other file.

    You add
    using Microsoft.Office.Interop.Excel;
    directive and the rest is straight forward.

    You must also add
    Microsoft.Office.Interop.Excel as reference from Add Reference.

    1 Sheets WRss = null;
    2 _Worksheet WRws = null;
    3
    4 string baseFile = Server.MapPath(".") + "\\MyTemplate.xls";
    5 string newFile = Server.MapPath(".") + "\\MyFile.xls";
    6
    7 Microsoft.Office.Interop.Excel.Application oExcel =
    8 new Microsoft.Office.Interop.Excel.Application();
    9
    10 oExcel.Workbooks.Open(baseFile, Type.Missing, false,
    11 Type.Missing, Type.Missing, Type.Missing,
    12 Type.Missing, Type.Missing, Type.Missing,
    13 Type.Missing, Type.Missing, Type.Missing,
    14 Type.Missing, Type.Missing, Type.Missing);
    15
    16 WRss = (Sheets)oExcel.Worksheets;
    17 WRws = (_Worksheet)(WRss.get_Item(1));
    18
    19 WRws.Cells.Font.Size = 12;
    20
    21 WRws.Cells[7, 3] = "Write Sometyhing";
    22
    23 if (System.IO.File.Exists(newFile))
    24 System.IO.File.Delete(newFile);
    25
    26 oExcel.Workbooks[1].SaveAs(newFile, Type.Missing,
    27 Type.Missing, Type.Missing, Type.Missing, false,
    28 Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
    29 Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    30
    31 oExcel.Workbooks.Close();
    32 oExcel.Quit();
    33
    34 Response.Clear();
    35 Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
    36 Response.AppendHeader("Content-disposition",
    37 "attachment; filename=MyFile.xls");
    38 Response.TransmitFile(newFile);


    NOTE: if you get the

    How to download file at ASP?

    How to download file at ASP.NET?
    How to download file in ASP?

    1 string newFile = Server.MapPath(".") + "\\MyFile.xls";
    2 Response.Clear();
    3 Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
    4 Response.AppendHeader("Content-disposition", "attachment; filename=Hesabat.xls");
    5 Response.TransmitFile(newFile);

    How to get table list by SQL?

    We can get list of tables in our database:

    1 SELECT
    2 TABLE_SCHEMA,
    3 TABLE_NAME,
    4 OBJECTPROPERTY(object_id(TABLE_NAME),
    5 N'IsUserTable') AS type
    6
    7 FROM
    8
    9 INFORMATION_SCHEMA.TABLES

    Reference

    How to handle Invalid postback or callback argument ERROR at ASP.NET?

    Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

    Solution:

    Add enableEventValidation="false" tag to the pages element of web.config.

    How to get variables by url in ASP?

    Suppose you access the url:

    http://www.mydemosite/Default.aspx?var1=100&var2=200


    In C# ASP.NET code you access the variables var1 and var2 like:

    1 string urlVar1 = Request.QueryString["var1"];
    2 string urlVar2 = Request.QueryString["var2"];

    How to highlight your code?

    You can highlight (with funny colors) your code by www.formatmycode.com

    How to connect to SQL Server from ASP?

    How to connect to SQL Server (MSSQL) from ASP.NET (C#)?
    How to connect to SQL Server from ASP.NET (C#)?
    How to connect to SQL Server from ASP.NET?

    // Main Code

    1 string connectionString = "Data Source=DatabaseSERVER\SQLEXPRESS;Initial
    Catalog=DatabaseName;Persist Security
    Info=True;User ID=yourUserName;Password=yourPassword
    "

    2
    3 db myDatabaseObject = new db(connectionString);
    4
    5 DataSet myDataSet = new DataSet();
    6
    7 myDatabaseObject.GetDbData("SELECT * FROM TableName", myDataSet);




    // Create a class named db including code below
    1 using System;
    2 using System.Data;
    3 using System.Configuration;
    4 using System.Web;
    5 using System.Web.Security;
    6 using System.Web.UI;
    7 using System.Web.UI.HtmlControls;
    8 using System.Web.UI.WebControls;
    9 using System.Web.UI.WebControls.WebParts;
    10 using System.Data.SqlClient;
    11 using System.Collections;
    12
    13 /// <summary>
    14 /// Database class includes database operation methods.
    15 /// </summary>
    16 public class db
    17 {
    18 SqlConnection connection = null;
    19 string query = "";
    20 bool dbResult = false;
    21 DataSet dataSet = null;
    22 string[] tables = { "Table1", "Table2", "Table3", "Table4" };
    23 enum dbTables: int
    24 {
    25 Table1,
    26 Table2,
    27 Table3,
    28 Table4
    29 }
    30
    31
    32 public db(string connectionString)
    33 {
    34 connection = new SqlConnection(connectionString);
    35 connection.Open();
    36 }
    37
    38 public SqlConnection Connection
    39 {
    40 get
    41 {
    42 return connection;
    43 }
    44 set
    45 {
    46 connection = value;
    47 }
    48 }
    49
    50 public void CloseDbConnection()
    51 {
    52 connection.Close();
    53 }
    54
    55 public bool GetDbData(string query, ref DataSet ds)
    56 {
    57 try
    58 {
    59 SqlCommand cmd = new SqlCommand();
    60 cmd.CommandTimeout = 0;
    61 cmd.Connection = connection;
    62 cmd.CommandText = query;
    63 cmd.CommandType = CommandType.Text;
    64 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
    65 {
    66 ds = new DataSet();
    67 da.Fill(ds);
    68 cmd.Parameters.Clear();
    69 }
    70 return true;
    71 }
    72 catch
    73 {
    74 return false;
    75 }
    76 }
    77
    78 public bool WriteDbData(string query)
    79 {
    80 try
    81 {
    82 SqlCommand addCatCommand = new SqlCommand();
    83 addCatCommand.Connection = connection;
    84 addCatCommand.CommandText = query;
    85 addCatCommand.ExecuteNonQuery();
    86 return true;
    87 }
    88 catch
    89 {
    90 return false;
    91 }
    92 }
    93 }

    How to show message box in ASP?

    How to show message box in ASP.NET (C#)?
    How to show message box in ASP C#?

    // C# code

    1 Response.Write(<script>alert('Hello')</script>);

    How to start process from ASP?

    How to start process from ASP.NET (C#)?
    How to start process from ASP.NET?
    How to start process from ASP?

    //C# code

    1 Process pr = new Process();
    2 pr.StartInfo.FileName = "notepad.exe";
    3 pr.Start();

    How to use cursors at SQL Server?

    How to use cursors at MSSQL?

    1 DECLARE @dummy VARCHAR(50)
    2 DECLARE @myOutput VARCHAR(50)
    3
    4 DECLARE db_cursor CURSOR FOR
    5 SELECT fieldName
    6 FROM tableName
    7
    8 OPEN db_cursor
    9 FETCH NEXT FROM db_cursor INTO @dummy
    10
    11 WHILE @@FETCH_STATUS = 0
    12 BEGIN
    13 SET @myOutput = @dummy
    14 PRINT @myOutput
    15 FETCH NEXT FROM db_cursor INTO @dummy
    16 END
    17
    18 CLOSE db_cursor
    19 DEALLOCATE db_cursor