Friday, November 26, 2010

What is other use of Go statement in TSQL?

I will explain you this with an Example.


CREATE TABLE dbo.TEST (ID INT IDENTITY (1,1), ROWID uniqueidentifier)
GO
INSERT INTO dbo.TEST (ROWID) VALUES (NEWID()) 
GO 1000

Note Second Go 1000.  This will insert 1000 row to table test.

Tuesday, November 23, 2010

Show tooltip text in gridview row on mouseover.

This Code segment explains, How to show tooltip text in gridview row on mouseover from Code behind

C# Code
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType e == DataControlRowType.DataRow)
{
//ShowToolTip
e.Row.ToolTip = "This text needs to shown on mouseover of the row!";
}
}

VB.NET
protected sub GridView_RowDataBound(ByVal sender As Object, e as GridViewRowEventArg)
if e.Row.RowType e = DataControlRowType.DataRow then
'ShowToolTip
e.Row.ToolTip = "This text needs to shown on mouseover of the row!";
End if
End Sub

How to Call print Dialog Box from JavaScript.

The Code segment show you, How to call print Dialog Box from JavaScript.

It is Very Simple, Just call window.print() function from java script
See Sample below…



<a href="JavaScript:window.print();">
<img src="set the image name" border="0"
width="17" height="17" align="middle" alt="Print Version" />
</a>

Thursday, October 21, 2010

Regular expressions in C#

Regular expressions are addictive. Playing with these compressed but powerful patterns is better than solving a Sudoku.

If you are wondering what this is all about because, obviously, regular expressions are just the use of “*?”, then read on because the truth is a lot more subtle and the result is a lot more powerful than you might suspect. Equally, regular expressions are something that you will find in more than just C#, they are useful in JavaScript, Perl, Java, Ruby and even in applications such as word processors.


Read more , Click here

Explain Linked Sever and How Add a Linked server?

Linked servers are a way to link to different OLEDB compatible data sources from within SQL Server. Here I am Explains the Concept with an example.

And Also How Add a Linked server?

Read it here

Wednesday, October 20, 2010

Find out Free disk space using SQL query

This code demonstrates use of master.sys.xp_fixeddrives. This returns all the drives available in the server and its free space in MB

Exec master.sys.xp_fixeddrives



RESULT

Drive MB Free
***** *******
C 10002
D 20002
F 57481


This will be very useful before large data load operation. We can check the disk space before starting the any large data load processes

Monday, October 18, 2010

do u know that windows XP is having a hidden "Star Wars Movie" inside it???

do u know that windows XP is having a hidden "Star Wars Movie" inside it???

You should be connected to the INTERNET for using this.

Go to Starts-->Programs-->Run
Type
telnet towel.blinkenlights.nl

And hit enter......... Enjoy the magic!!!!

Saturday, October 16, 2010

How to Enable CLR integration in SQL Server

This code segment explain you, How to Enable CLR integration in SQL Server using TSQL

To enable CLR integration in SQL Server, Use follwing TSQL statment.



EXEC sp_configure 'clr enabled', 1;

RECONFIGURE WITH OVERRIDE;

GO;



similarly for Disabling use follwing.



EXEC sp_configure 'clr enabled', 0;

RECONFIGURE WITH OVERRIDE;

GO ;

Thursday, October 14, 2010

C# code for Lock windows

This simple code segment explain you, How to lock windows using C# code (same as pressing Windows logo key and the letter L)




This is nothing but calling of “C:\WINDOWS\system32\rundll32.exe user32.dll, LockWorkStation” command from C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;


namespace Sajid.LockComputer

{

class Program
{
static void Main(string[] args)
{
Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation") ;
}
}
}

XML to HTML transformation using Xslt

Namespace Required:

1. System.Xml
2. System.Xml.XPath
3. System.Xml.Xsl

public static void Transform(string sXmlPath, string sXslPath)

{

try

{

// Step 1: load the Xml doc

XPathDocument myXPathDoc = new XPathDocument(sXmlPath) ;

XslTransform myXslTrans = new XslTransform() ;



// Step 2: load the Xsl

myXslTrans.Load(sXslPath) ;



// Step 3: create the output stream



XmlTextWriter myWriter = new XmlTextWriter("result.html", null);



// Step 4: do the actual transform of Xml





myXslTrans.Transform(myXPathDoc,null, myWriter);

myWriter.Close() ;

}

catch(Exception e)

{

Console.WriteLine("Exception: {0}", e.ToString());

}

}

Change SQL Server Authentication Mode Using TSQL

We can use undocumented procedure xp_regwrite/xp_instance_regwrite, to change the authentication mode form query.


exec master..xp_instance_regwrite N'HKEY_LOCAL_MACHINE',N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer','LoginMode', N'REG_DWORD', 2

0 or 2 => Mixed Mode

1 => integrated

Wednesday, October 13, 2010

How to Format A Excle Column.

Summary : This Code Code Snippets Guide you to format EXCEL Column progrmaticaly. Here i am doing number formating

Follwing is the COde for formating the first Column of EXcel sheet. You Have to change the Column index of cell to format the required column

VB.NET

Dim Wb As Excel.Workbook =
Dim xWS As Excel.Worksheet
xWS = Wb.ActiveSheet
CType(xWS.Cells(1, 1), Excel.Range).EntireColumn.NumberFormat = "#,##0.00"

C#


Excel.Workbook wb = ;
Excel.Worksheet xWS;
xWS = wb.ActiveSheet;
Excel.Range rng = xWS.Cells[1,1] as Excel.Range;
rng.EntireColumn.NumberFormat = "#,##0.00";

Tuesday, October 12, 2010

5 Traps to Avoid in C#

C# Corner columnist Patrick Steele offers a heads up on five gotchas that can trip up even veteran C# programmers. This is Very usefull for C# programmers

Clik here to view the post

Monday, October 11, 2010

How to Convert Image to Binary String?

Here you will learn How Convert Image to Binary String using of C# and the .NET Framework.

Basically, the program "reads" the image pixel by pixel, and where there is a pixel that is something else than white it will Append 1, else 0 in the string.

private string ConvertoToString(string imagePath)
{
string text = "";
System.Drawing.Bitmap bitMap = new Bitmap(imagePath);
for (int i = 0; i < bitMap.Height; i++)
{
for (int j = 0; j < bitMap.Width; j++)
{
if (bitMap.GetPixel(j, i).A.ToString() == "255" && bitMap.GetPixel(j, i).B.ToString() == "255" && bitMap.GetPixel(j, i).G.ToString() == "255" && bitMap.GetPixel(j, i).R.ToString() == "255")
{
text = text + "0";
}
else
{
text = text + "1";
}
}
text = text + "";
}
return ( text);
}

How to capture/store screen shot

Here I am trying to simulate "print screen" using C#.

We all are familiar with taking screen shot manully by pressing "Print Screen" key. There are two alternative for using "Print Screen" key

1) Alt+PrtScn -Image of active screen
2) PrtScn - Image of Desktop



Follwing is the code for that.

///
/// capture/store the screen shot
///

/// true-Active screen
/// image
public static Image GetScreenShot(bool currentScreen)
{

if (currentScreen)
// Simulate Alt+PrtScn keypress.
SendKeys.Send("{%}({PRTSC})");
else
// Simulate PrtScn keypress.
SendKeys.Send("{PRTSC}");

// Get the image from the clipboard.
return (Image)Clipboard.GetImage();

}



In the above example, GetScreenShot() function gets the screen shot and returns an Image object from the Clipboard.

Get Contact information from outlook using C#

The following Code sample guide you to get contact information form outlook ( 2003 or 2007). Before using this code, you need to refer “Microsoft outlook object libary “ in you project .

Note 1: To execute this code outlook must be running in the machine.

Note 2: You have to create an alias for a namespace “Microsoft.Office.Interop.Outlook”
like using Outlook = Microsoft.Office.Interop.Outlook;


private List GetContacts(string findLastName)
{
List foundContacts = new List();
Outlook.Application outlookApp = new Outlook.ApplicationClass();
Outlook.MAPIFolder folderContacts = outlookApp.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Microsoft.Office.Interop.Outlook.Items searchFolder = folderContacts.Items;
foreach (Microsoft.Office.Interop.Outlook.ContactItem foundContact in searchFolder)
{
if (foundContact.LastName.Contains(findLastName))
{
foundContact.Display(false);
foundContacts.Add(foundContact);
}
} return foundContacts;
}

Saturday, October 9, 2010

Send a mail, whenever a new record is inserted in a table using Sqlserver 2000

Here, we have to create a trigger on required table as show below.


CREATE TRIGGER reminder2
ON TableX
AFTER INSERT
AS

EXEC master..xp_sendmail
@recipients='you@you.com',
@message = 'body'
@subject = 'foo was fired.'
GO

Find out particular row form grid view using LINQ

Usually getting a row from Grid view, we will loop thou the grids row collection and check for Specific conditions.

GridViewRow SelectedRow;

foreach (GridViewRow gr in GridView1.Rows)
{
if ( gr.Cells[1].ToString() == "Value1" && gr.Cells[2].ToString() == "Value2")
{
SelectedRow = gr; break;
}
}

But using LINQ we can write same thing as more readable manners as given below.

GridViewRow SelectedRow = GridView1.Rows.OfType().FirstOrDefault(row => row.Cells[1].ToString() == "Value1" && row.Cells[2].ToString() == "Value2");