Search This Blog

Friday, November 23, 2012

How to find jobs associated to a sql table?

Select sj.* from MSDB.dbo.sysjobsteps ss
Inner Join msdb..sysjobs sj On sj.job_id = ss.job_id
Where ss.command like '%tblUser%'



oR

select sj.*
from MSDB.dbo.sysjobsteps ss
inner join MSDB.dbo.sysjobs sj
on sj.job_id=ss.job_id,
(select so.*
from sysobjects so
inner join syscomments sc
on sc.id=so.id
where so.type='p'
and sc.text like '%tblUser%'
)aa
where ss.command like '%tblUser%'
or
ss.command like '%'+ aa.name +'%'

Tuesday, October 30, 2012

how to check pc start time?

open command prompt and run the following command.

C:\users\arvibk>syteminfo | find /i "boot time"

Wednesday, October 10, 2012

How to set event and attribute to a control from javascript.

var objMy = document.getElementById("ddlMy"); //objMy.setAttribute(name,value); objMy.setAttribute("onchange","test();"); function test() { alert('test'); }

Friday, September 28, 2012

How to disable, enable and drop an Index in SQL?

-- Disable Index in table tblUser
ALTER INDEX IX_tblUser ON tblUser DISABLE;

-- Enable Index in table tblUser
ALTER INDEX IX_tblUser ON tblUser REBUILD;

--DROP Index from table tblUser
DROP INDEX IX_tblUser ON tblUser

Thursday, September 13, 2012

How to read content of a html page using c#

// Way 1
using System.Net;
//...
using (WebClient client = new WebClient ()) // WebClient class inherits IDisposable
{
// save content into a file client.DownloadFile("http://myweb.com/page.html", @"C:\localfile.html");

// Or you can get the file content without saving it:
string htmlCode = client.DownloadString("http://myweb.com/page.html");
//...
}
// Way 2
/***********Read From same Application************/
using System.IO;
StreamReader sr = new StreamReader(Server.MapPath("Status.htm"));
string strS = sr.ReadToEnd();


//Way 3
/***************Read From Secure Wdb Site***********************/
//Read from secure website 'https'

Dim strRptHtml As String
Dim objResponse As WebResponse
Dim objRequest As WebRequest = HttpWebRequest.Create(strURL + "status.htm") ''''https://newqa.nccecas.org/cecas/status.htm objResponse = objRequest.GetResponse()
Using sr1 As New StreamReader(objResponse.GetResponseStream())
strRptHtml = sr1.ReadToEnd()
sr1.Close()
End Using
objResponse.Close()

Tuesday, September 11, 2012

What is an alternative of CURSOR in SQL?

The alternative of CURSOR depends on what the developers want to perform.
On the basis of your task you can use the following to avoid cursor..
1. WHILE loop
2. User defined function
3. Temporary Table
4. Joined complex sql query etc..


Note: Sometimes the use of cusor becomes better than its' alternative. Because sometime alternative takes more execution time than cursor.

Ranking Functions in SQL.

There are four ranking funtion in SQL
1. RANK
2. NTILE
3. DENSE_RANK
4. ROW_NUMBER

See the example and output result set to know about these...
USE MyDatabase;
GO
SELECT p.FirstName, p.LastName
    ,ROW_NUMBER() OVER (ORDER BY a.PostalCode) AS "Row Number"
    ,RANK() OVER (ORDER BY a.PostalCode) AS Rank
    ,DENSE_RANK() OVER (ORDER BY a.PostalCode) AS "Dense Rank"
    ,NTILE(4) OVER (ORDER BY a.PostalCode) AS Quartile
    ,s.SalesYTD, a.PostalCode
FROM Sales.SalesPerson AS s 
    INNER JOIN Person.Person AS p 
        ON s.BusinessEntityID = p.BusinessEntityID
    INNER JOIN Person.Address AS a 
        ON a.AddressID = p.BusinessEntityID
WHERE TerritoryID IS NOT NULL 
    AND SalesYTD <> 0;

FirstName

LastName

Row Number

Rank

Dense Rank

Quartile

SalesYTD

PostalCode

Michael

Blythe

1

1

1

1

4557045.0459

98027

Linda

Mitchell

2

1

1

1

5200475.2313

98027

Jillian

Carson

3

1

1

1

3857163.6332

98027

Garrett

Vargas

4

1

1

1

1764938.9859

98027

Tsvi

Reiter

5

1

1

2

2811012.7151

98027

Shu

Ito

6

6

2

2

3018725.4858

98055

José

Saraiva

7

6

2

2

3189356.2465

98055

David

Campbell

8

6

2

3

3587378.4257

98055

Tete

Mensa-Annan

9

6

2

3

1931620.1835

98055

Lynn

Tsoflias

10

6

2

3

1758385.926

98055

Rachel

Valdez

11

6

2

4

2241204.0424

98055

Jae

Pak

12

6

2

4

5015682.3752

98055

Ranjit

Varkey Chudukatil

13

6

2

4

3827950.238

98055

How to generate serial number in sql without using identity column?

In sql, there is a method Row_Number() using which you can generate sr. no.

Example:

SELECT Row_Number() Over(Order by ID) AS SrNo , colmn1, colmn2....
FROM tblTemp

Output
SrNo Colmn1 Column2 ...
1 .. .. ..
2 .. .. ..
3 .. .. ..

Monday, September 10, 2012

Reverse For Loop in VB.net.

Reverse Loop
For i = 8 to 1 step -1

Next


Forward loop
For i = 8 to 1

Next

Thursday, August 30, 2012

How to create a linked server?

Use the following sql script to create a linked server
EXEC sp_addlinkedserver
   @server=N'RPT_SRV', -------Linked Server Name
   @srvproduct=N'', ---- Product dy default blank
   @provider=N'SQLNCLI', ----- Provider name for sql server
   @datasrc=N'172.16.0.15\SQL2008'; -- Database source name (SQL Server instance)

Tuesday, July 17, 2012

The provider ran out of memory

Error:
The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" reported an error. The provider ran out of memory.

Cause:
This error comes when we execute the following code and sql instance has been expired.

Query
SELECT * INTO #tmp
FROM
OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0','Data Source=\\198.1.110.15\d$\Inetpub\wwwroot\WebSite2\FutureKPA\EmpProductivity.xls;Extended Properties=''Excel 8.0;HDR=Yes''')...[Sheet1$]

Solution:
Relogin to SQL Server.

Saturday, June 9, 2012

How to display a button on rightclick in a listbox?

Use the bellow code to display a Context Menu on right click..
Here a button is as context menu.
Javascript:

<script type="text/javascript">
    function callme(x) {
       var MainContent_btnX = document.getElementById("MainContent_btnX");
       MainContent_btnX.style.display = 'block';
       //alert(x);
    }

</script>

ASP.Net
<asp:Button ID="btnX" runat="server" OnClick="btnX_Click" Text="Test Transaction" style="position:absolute;z-index:999;display:none" />
<asp:ListBox ID="lstBox" runat="server" oncontextmenu="callme('1');">
    <asp:ListItem Text="Good">1</asp:ListItem>
    <asp:ListItem Text="Morning"> 2</asp:ListItem>
</asp:ListBox>

Tuesday, June 5, 2012

how to set custom date format in javascript?

function parseDate(input, format)
{
  format = format || 'dd/mm/yyyy'; // somedefault format
   var parts = input.match(/(\d+)/g),
   i = 0, fmt = {};
   // extract date-part indexes from the format
   format.replace(/(yyyy|dd|mm)/g, function(part) { fmt[part] = i++; });
   return new Date(parts[fmt['yyyy']], parts[fmt['mm']]-1, parts[fmt['dd']]);
}


Usage
parseDate('01-31-2010', 'mm-dd-yyyy');
parseDate('31/01/2010', 'dd/mm/yyyy');
parseDate('2010/01/31');

Invalid object name "Tempdb.dbo.ASPStateTempApplications"

Execute the below script to solve the error : Invalid object name = 'tempdb.dbo.ASPStateTempApplications'.

USE [ASPState]
GO

DECLARE @return_value int

EXEC @return_value = [dbo].[CreateTempTables]

SELECT 'Return Value' = @return_value

GO

Monday, June 4, 2012

how to populate cascading dropdownlist in javascript?

You can force it to populate by setting a different index.
<script type="text/javascript">
function pageLoad()
{
var cde = $find('test_cascade');
cde.set_contextKey("not raymond");
var parent = $get(cde.get_ParentControlID());
var index = parent.selectedIndex;
parent.selectedIndex = -1;
cde._onParentChange(null, false);
parent.selectedIndex = index;
cde._onParentChange(null, false);
}
</script>



<asp:DropDownList id= "ddl_state" runat="server" ></asp:DropdownList>
<asp:DropDownList id= "ddl_dist" runat="server" ></asp:DropdownList>
<ajaxToolkit:CascadingDropDown id="CascadingDropDown1" runat="server" ServicePath="WebService.asmx" ServiceMethod="GetAllDistrict" ParentControlID="ddl_state" TargetControlID="ddl_dist" Category="Districts" UseContextKey="true" LoadingText="Loading District" PromptText="Select a District" BehaviorID="test_cascade"> </ajaxToolkit:CascadingDropDown>

Friday, May 18, 2012

How to check your page is valid?

function ValidatePage() {

if (typeof (Page_ClientValidate) == 'function') {
Page_ClientValidate();
}

if (Page_IsValid) {
// do something
alert('Page is valid!');
}
else {
// do something else
alert('Page is not valid!');
}
}

Thursday, May 3, 2012

How to rerturn value from showmodaldialog

Using the following javascript code you can return a variant value from modaldialog window to parent window.
When you call showModalDialog you do this:
Code:
var oReturnValue = window.showModalDialog("subDoc.html",argsVariable, "dialogWidth:300px; dialogHeight:200px; center:yes");
Within showModalDialog, assuming your textboxes have IDs of "txtForename" and "txtSurname":
Code:
function terminate()
{
var o = new Object();
o.forename = document.getElementById("txtForename").value;
o.surname = document.getElementById("txtSurname").value;
window.returnValue = o;
}


Then continuing in your main window:
Code:

alert(oReturnValue.forename + "\n" + oReturnValue.surname);

Wednesday, April 11, 2012

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "AjaxControlToolkit.Properties.Resources.NET4.re

Error Message:


Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "AjaxControlToolkit.Properties.Resources.NET4.resources" was correctly embedded or linked into assembly "AjaxControlToolkit" at compile time, or that all the satellite assemblies required are loadable and fully signed

Resaon :


AjaxControlToolkit’s control load reference refers to the base System.Web.UI.Control method which is present as a part of the ASP.NET AJAX Libraries and those libraries are referenced only when the ScriptManager is referenced in the page.

Solution:


Add ScriptManager in the page and this error would be resolved.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>