Tuesday, November 8, 2011

Apply Distinct on Datatable

 

DataView view = new DataView(table);
DataTable distinctValues = view.ToTable(true, "Column1", "Column2" ...);

 

Thursday, October 27, 2011

winscp.exe COPIES FILES FROM UNIX TO WINDOWS

 

set LOGINAS=username:password@host

 

set SOURCE_PATH=/local/home

set DEST_PATH=d:\Test\

set SCRIPT_FILE=script.txt

 

set _Date=%date%

 

If "%_Date%A" LSS "A" (Set _NumTok=1-3) Else (Set _NumTok=2-4)

:: Default Delimiter of TAB and Space are used

For /F "TOKENS=2*" %%A In ('REG QUERY "HKCU\Control Panel\International" /v iDate') Do Set _iDate=%%B

For /F "TOKENS=2*" %%A In ('REG QUERY "HKCU\Control Panel\International" /v sDate') Do Set _sDate=%%B

IF %_iDate%==0 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%D%%B%%C

IF %_iDate%==1 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%D%%C%%B

IF %_iDate%==2 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%B%%C%%D

Set _Today=%_fdate:~0,4%%_fdate:~4,2%%_fdate:~6,2%

 

set COPYFILE_1_PATRN=A1_TEST_%_Today%.txt

set COPYFILE_2_PATRN=B1_TEST_%_Today%.txt

 

Echo option batch abort>>%SCRIPT_FILE%

Echo option confirm off>>%SCRIPT_FILE%

Echo open %LOGINAS%>>%SCRIPT_FILE%

Echo cd %SOURCE_PATH%>>%SCRIPT_FILE%

Echo option transfer binary>>%SCRIPT_FILE%

Echo get %COPYFILE_1_PATRN% %DEST_PATH%>>%SCRIPT_FILE%

Echo get %COPYFILE_2_PATRN% %DEST_PATH%>>%SCRIPT_FILE%

Echo close>>%SCRIPT_FILE%

Echo exit>>%SCRIPT_FILE%

 

 

"C:\Program Files\WinSCP\winscp.exe" /console /script=%SCRIPT_FILE%

DEL %SCRIPT_FILE%

PAUSE

 

 

Tuesday, September 27, 2011

value from the enum ?

Question:

      Is there any way that I can access the assigned value from the enum?

 

                Eg: When my item is Red then I want get the corresponding value That’s ‘R’. Is that possible?

public enum Color

      {

          Red = 'R',

          Blue = 'B',

          Green ='G',

          Yellow ='Y',

          White = 'W'

      }

 

Answer:

 

Yes by this way –

 

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine((char)Color.Red);

        }

    }

 

    public enum Color

      {

          Red = 'R',

          Blue = 'B',

          Green ='G',

          Yellow ='Y',

          White = 'W'

      }

 

Friday, September 23, 2011

Tracking CPU and Memory usage per process

Just type perfmon into Start > Run and press enter. When the Performance window is open, click on the + sign to add new counters to the graph. The counters are different aspects of how your PC works and are grouped by similarity into groups called "Performance Object".

 

For your questions, you can choose the "Process", "Memory" and "Processor" performance objects. You then can see these counters in real time

 

You can also specify the utility to save the performance data for your inspection later. To do this, select "Performance Logs and Alerts" in the left-hand panel. (It's right under the System Monitor console which provides us with the above mentioned counters. If it is not there, click "File" > "Add/remove snap-in", click Add and select "Performance Logs and Alerts" in the list".) From the "Performance Logs and Alerts", create a new monitoring configuration under "Counter Logs". Then you can add the counters, specify the sampling rate, the log format (binary or plain text) and log location.

 

 

For more information follow this link.

 

http://stackoverflow.com/questions/69332/tracking-cpu-and-memory-usage-per-process

Wednesday, August 10, 2011

Spool in unix

Login to oracle

Sqlplus user/pwd@database

 

Spool filename.txt

Select * from dual;

Spool off

 

 

Saturday, July 9, 2011

Deligates small note.

Delegates in C# are objects which points towards a function which matches its signature. Delegates are reference type used to encapsulate a method with a specific signature. Delegates are similar to function pointers in C++; however, delegates are type-safe and secure.
Here are some features of delegates:

A delegate represents a class.
A delegate is type-safe.
We can use delegates both for static and instance methods
We can combine multiple delegates into a single delegate.
Delegates are often used in event-based programming, such as publish/subscribe.
We can use delegates in asynchronous-style programming.
We can define delegates inside or outside of classes.
Syntax of using delegates

//Declaring delegate
delegate void SampleDelegate(string message);

// declare method with same signature:
static void SampleDelegateMethod(string message) { Console.WriteLine(message); }

// create delegate object
SampleDelegate d1 = SampleDelegateMethod;

// Invoke method with delegate
d1("my program");

Monday, June 20, 2011

How to install a Windows service using command line ?

How to install a Windows service using command line ?

1>> Make a build of the service project then go to bin directory and copy required build files from either of the directory Release / Debug.
2>> Service will be in .exe file. This should be installed now, by using a command line   as below –

Copy blow one to bat file , name it as install.bat.

c:
cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
InstallUtil.exe "E:\test\testservice.exe"
pause


Run install.bat to install the service.

3> To uninstall there are two ways –
               a)
c:
cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
InstallUtil.exe –u "E:\test\testservice.exe"
pause

b)
sc delete <serviceName>
pause

               Some time using point number 3.a  , it is required to restart the windows machine so better to use the point 3.b.



Note- if you struck with the service which is already installed then you can kill that process , either using command line or ctrl+Alt+del select service and kill the process.

Friday, June 17, 2011

How to remove item from a List in a Loop ?

It is not an easy task of removing an item from the list in the loop. By just doing the loop and removing the item we can encounter much complications.

So better way is to loop the list from bottom -> up and remove the item based on the condition.

Sample code piece -



using System;
using System.Collections.Generic;
using System.Text;
using System.IO;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            List<string> ls = new List<string>();

            ls.Add("a");
            ls.Add("b");
            ls.Add("c");
            ls.Add("d");
            ls.Add("e");

            for (int i = ls.Count - 1; i >= 0; i--)
            {


                if (ls[i] == "d")
                {
                    Console.WriteLine("del:" + ls[i].ToString());
                    ls.RemoveAt(i);
                }

            }

            for (int i = 0; i < ls.Count; i++)
            {
                Console.WriteLine(ls[i].ToString());
            }

        }
    }
}

Tuesday, May 3, 2011

Case Sensitive search In Microsoft SQL Server,

In Microsoft SQL Server, in that the case if you query for some thing with where clause which is  case sensitivity search then you have to follow as below.

declare @addr nvarchar(20)

set @addr ='123 strEet'

select @addr where @addr  like '%ree%'
select @addr where @addr  like '%rEe%'

select @addr where @addr COLLATE SQL_Latin1_General_CP1_CS_AS like '%ree%'
select @addr where @addr COLLATE SQL_Latin1_General_CP1_CS_AS like '%rEe%'

Thursday, April 21, 2011

Remove Duplicates in Microsoft Sql server

There are many ways to do that but most probably it would be much round trip , here is the simple way of removing the duplicates.

insert into santest values (1,'A')
insert into santest values (1,'A')
insert into santest values (1,'A')
insert into santest values (2,'B')
insert into santest values (2,'B')
insert into santest values (3,'C')
insert into santest values (3,'C')

WITH tbl_del AS (
SELECT *,ROW_NUMBER () OVER (
PARTITION BY id,name ORDER BY id ) AS Rnum
FROM santest)

DELETE FROM tbl_del WHERE Rnum > 1

Tuesday, March 22, 2011

The user is not associated with a trusted SQL Server connection. (.Net SqlClient Data Provider)

I was also facing this issue every time I install the sql server. It occurs initially and once we fix this then onwards it disappears. I have followed the instructions explained in the below blog post. It was very useful to me. I hope you will also like it.

http://cherupally.blogspot.com/2009/04/user-is-not-associated-with-trusted-sql.html

 

Tuesday, March 15, 2011

CVS Version Control on Windows in 10 minutes

CVS Version Control on Windows in 10 minutes

 

Do you need a reliable version control for your website, personal notes, transferring data from work to home to university back & forth without any costs in time or budget?

Do you still don’t want to setup a Linux machine just because CVS requires Linux for stable use (like some dude told you ages ago?)

Do you not want to hassle around with flimsy Unix-stuff but only have convenient Version Control in a manner like PCVS or Microsoft VSS ??

Well just take CVS (CVSNT 2.x) and TortoiseCVS / WinCVS for your home/laptop/school machine and become happy with it… you don’t need anything else and get used to open-source industry-proven version and configuration management control.

Read on for a setup-howto consisting mainly of links to relevant pages and tools…

1) you need the CVSNT – version 2.x – for running the CVS server itself on your windows box. If you have a Linux-server, then forget this step and look up ordinary CVS on Linux setup guides… else

a) download the latest CVSNT 2.0.8 and start the setup. Don’t forget to install the services (Which are the actual CVS server services running in the background…) do a reboot afterwards, or you will receive some errors when creating your repository

b) checkout this Beginners guide to CVS for more detailled installation tips (i.e. user management)... I assume you simply install the stuff on your single PC/notebook with local users.

c) after Reboot your will have a panel “CVS For NT” in your Control Panel http://www.cvsnt.org/files/InstallationTips/attachments/Configure-1.png

2) The following steps explain a basic repository installation

a) stop the service in the CVS for NT panel

b) now create a repository for your PC – the repository is the directory where the internal representation of your version files are stored – sort of file-database…

c) Go to the tab “Repositories” and with a “prefix” of e.g. “c:\cvsrepos” you can define this basic path, which will be common for all repositories… Note: one repository is only a collection of many modules (which could be different projects )...

d) Use the Add button to add a repository. Enter TEST after the prefix in the box that appears. Accept the offer to create the repository. Again: You can have several separate repositories on the same server, in that case you will use the Add button once for each repository you need. Once the list of repositories contain those you want you are done here.

e) Go to the tab “ Advanced” and setup your temp-path to e.g. “c:\cvstemp”

e) Start the service again

3) The following steps explain a basic user setup – instead of localhost you can put in your IP or real hostname… these commands have to be performance in a commandline-window (CMD.EXE)

a) set cvsroot=:sspi:localhost:/TEST

b) cvs passwd -r {real account name} -a {new username}

e.g. cvs passwd -r Administrator -a Adminstrator

—- then enter the password on the commandline

Any user entered like this MUST be an NT user on the local system!

More tips to be found in this documentation about adding users to CVS if necessary, but for the first test it will be ok.

4) now for the connection testing – these commands have to be performance in a commandline-window (CMD.EXE)

a) set cvsroot=:{protocol}:{user}@{computername}:/TEST

e.g. set cvsroot=:pserver:Administrator@localhost:/TEST

b) cvs login

—- then enter the password on the commandline

c) cvs ls -l -R

to perform a basic query – don’t worry – the gui stuff is comming up right away…

5) Install TortoiseCVS

TortoiseCVS is a great plugin for the windows explorer that provides you all the necessary CVS functions via right-click&select like other version control systems do… I prefer it much more over WinCVS for daily use, because the standard-tasks of check-out (cvs:“update”) or check-in(cvs:“commit”) can be done very easy and seamless with it…

Don’t forget to reboot or at least re-login man…

6) now we will perform a simple module-import… a module-import bring files initially into CVS.

a) create a directory TestModule

b) right-click “TestModule” : CVS -> Create New Module

c) Enter the CVSROOT you used above like

</p>
 
    :sspi:Administrator@localhost:2401:/test
 
        <p>

and press OK to enter this module into CVS – that’s ONLY the directory so far!

d) now put some files/directories in this “module”-directory

e) right-click “TestModule” : CVS : add contents to add all the contained files/directories

f) and now “Commit” these changes, means to finish this “transaction” with

g) right-click “TestModule” : CVS : check in (einchecken)

Now these files are in an initial revision in your CVS repository! Congratulations!

6) for more advanced use and topics I also recommend to install the WinCVS GUI front-end for CVS you can get here... I am already using the beta 1.3, so give it a try… also make sure to install Python 2.1.3 for advanced scripting features… I am not sure if 2.2 or 2.3 will work aswell!

7) Use above steps for other directories/projects you wish to version control and keep the following simple steps in mind:

a) Import Module for initial load to CVS – create a “clean” version of your files – deleting from CVS is a hassle

b) CVS Check-Out to get one module / project to your work-directory the first time as a sort of complete export

c) CVS Update to sync your local work-directory with the CVS repository

d) CVS Commit to “check-in” again and make sure everythings on the server…

More documentation is to be found in the CVS NT Reference Manual

so long for now…

Copied from  -

http://weblog.cemper.com/a/200307/28-cvs-version-control-on-windows-in-10-minutes.php

 

Monday, January 24, 2011

Kill process id in windows - force windows service to stop from stopping status


Kill process id in windows - force windows service to stop from stopping status

You can retrieve the PID for the process of the service through the command

sc queryex <servicename>

it returns some information like this

NOME_SERVIZIO: <servicename>
TIPO : 10 WIN32_OWN_PROCESS
STATO : 3 STOP_PENDING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
CODICE_USCITA_WIN32 : 0 (0x0)
CODICE_USCITA_SERVIZIO : 0 (0x0)
PUNTO_ARRESTO : 0x0
INDICAZIONE_ATTESA : 0x0
PID : 1824
FLAG :

Then you can stop the service by the command

taskkill /F /PID 1824 (the specific PID)


Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code