Monday, January 29, 2007

how to read a CSV file

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Odbc;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

DataTable dtRecords = GetDataTable("SELECT FirstName, LastName FROM members2.csv ");



foreach(DataRow dr in dtRecords.Rows) {
MessageBox.Show(dr["FirstName"].ToString() + " " + dr["LastName"].ToString() );
}


}



private static string GetConnection() {
return @"Driver={Microsoft Text Driver (*.txt; *.csv)};HDR=YES;Extensions=asc,csv,tab,txt;Dbq=C:\Temp";
}

public static DataTable GetDataTable(string sql) {
DataTable rt = new DataTable();
DataSet ds = new DataSet();
OdbcDataAdapter da = new OdbcDataAdapter();
OdbcConnection con = new OdbcConnection(GetConnection());
OdbcCommand cmd = new OdbcCommand(sql, con);
da.SelectCommand = cmd;
da.Fill(ds);
try {
rt = ds.Tables[0];
}
catch {
rt = null;
}
return rt;
}

public static void DoCommand(string sql) {
OdbcConnection con = new OdbcConnection(GetConnection());
OdbcCommand cmd = new OdbcCommand();
cmd.CommandText = sql;
cmd.Connection = con;
con.Open();
try {
cmd.ExecuteNonQuery();
}
catch (Exception e){
//HandleError(e,sql);
}
finally {
con.Close();
}
}
}
}

Thursday, January 25, 2007

Windows 2003 SP 1 Crack !!

last couple of months i was tring to install SP 1 On my pirated Windows 2003 Server. it just susks.. every time pirated copy error message comes.. i I did some thing trickey to get it done. so some of you also a guy like me .. I hope this will help you 2


First of all you have to download this and save your original key.

Magical Jelly Bean Keyfinder v1.51
http://www.magicaljellybean.com



Then You have to go here and get your Windows 2003 Activation Wizard to change the KEY
http://www.petri.co.il/change_the_serial_in_windows_xp.htm

and change the Key to this Key,

GXMMC-DFWVM-KPVBC-X3XGB-FXTBB

then u r ready to install Windows 2003 SP 1 On your Server...

Monday, January 22, 2007

Open a text file using .NET and read

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Odbc;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

DataTable dtRecords = GetDataTable("SELECT FirstName, LastName FROM members2.csv ");

foreach(DataRow dr in dtRecords.Rows) {
MessageBox.Show(dr["FirstName"].ToString() + " " + dr["LastName"].ToString() );
}


}



private static string GetConnection() {
return @"Driver={Microsoft Text Driver (*.txt; *.csv)};HDR=YES;Extensions=asc,csv,tab,txt;Dbq=C:\Temp";
}

public static DataTable GetDataTable(string sql) {
DataTable rt = new DataTable();
DataSet ds = new DataSet();
OdbcDataAdapter da = new OdbcDataAdapter();
OdbcConnection con = new OdbcConnection(GetConnection());
OdbcCommand cmd = new OdbcCommand(sql, con);
da.SelectCommand = cmd;
da.Fill(ds);
try {
rt = ds.Tables[0];
}
catch {
rt = null;
}
return rt;
}

public static void DoCommand(string sql) {
OdbcConnection con = new OdbcConnection(GetConnection());
OdbcCommand cmd = new OdbcCommand();
cmd.CommandText = sql;
cmd.Connection = con;
con.Open();
try {
cmd.ExecuteNonQuery();
}
catch (Exception e){
//HandleError(e,sql);
}
finally {
con.Close();
}
}
}
}

Friday, January 19, 2007

The Process of Database Refactoring

The Process of Database Refactoring
http://www.simple-talk.com/sql/database-administration/refactoring-databases-the-process/
http://www.red-gate.com/products/SQL_Refactor/index.htm

console applicationt to detect USB

one guy in the fourm has asked about how to detect USB in a console application and here is the code.. Yes if cource it with some help of the google !!!!


Imports System.Management

Module Module1

Private WithEvents m_MediaConnectWatcher As Management.ManagementEventWatcher


Sub Main()

Dim query As New WqlEventQuery("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE TargetInstance ISA ""Win32_DiskDrive""")
Dim watcher As New ManagementEventWatcher(query)

AddHandler watcher.EventArrived, AddressOf HandleEvent

' Start listening for events
watcher.Start()

Console.Read()

' Stop listening for events
watcher.Stop()
Return


End Sub


Private Sub HandleEvent(ByVal sender As Object, ByVal e As System.Management.EventArrivedEventArgs) Handles m_MediaConnectWatcher.EventArrived
Dim mbo, obj As ManagementBaseObject

' the first thing we have to do is figure out if this is a creation or deletion event
mbo = CType(e.NewEvent, ManagementBaseObject)
' next we need a copy of the instance that was either created or deleted
obj = CType(mbo("TargetInstance"), ManagementBaseObject)

Select Case mbo.ClassPath.ClassName
Case "__InstanceCreationEvent"
If obj("InterfaceType") = "USB" Then
MsgBox(obj("Caption") & " (Drive letter " & GetDriveLetterFromDisk(obj("Name")) & ") has been plugged in")
End If
Case "__InstanceDeletionEvent"
If obj("InterfaceType") = "USB" Then
MsgBox(obj("Caption") & " has been unplugged")
End If
End Select

End Sub

Private Function GetDriveLetterFromDisk(ByVal Name As String) As String
Dim oq_part, oq_disk As ObjectQuery
Dim mos_part, mos_disk As ManagementObjectSearcher
Dim obj_part, obj_disk As ManagementObject
Dim ans As String

' WMI queries use the "\" as an escape charcter
Name = Replace(Name, "\", "\\")

' First we map the Win32_DiskDrive instance with the association called
' Win32_DiskDriveToDiskPartition. Then we map the Win23_DiskPartion
' instance with the assocation called Win32_LogicalDiskToPartition

oq_part = New ObjectQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & Name & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition")
mos_part = New ManagementObjectSearcher(oq_part)
For Each obj_part In mos_part.Get()

oq_disk = New ObjectQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & obj_part("DeviceID") & """} WHERE AssocClass = Win32_LogicalDiskToPartition")
mos_disk = New ManagementObjectSearcher(oq_disk)
For Each obj_disk In mos_disk.Get()
ans &= obj_disk("Name") & ","
Next
Next

Return ans.Trim(","c)
End Function

End Module

Monday, January 08, 2007

Removing Unused or Problem Indexes

ahh one guy has done it... !!!! I have been looking for this quit some time and I found it today.

all you need is : sys.dm_db_index_usage_stats

http://www.sqlservercentral.com/columnists/aingold/2770.asp

Tuesday, January 02, 2007

x mas (x-men)

Just though of write about how I spend the last week of the year, All started on 23 rd
sta'day. In the morning we had a superb session on SQL Server By Dishesh Priyankara. I managed to learn da some
of da doubts I had on SQL Server.

after the session I went to enter-Sys to meet pitta and da rest of the guys, and played pool... Played against Cheena... damm..
I won 1 game after playing more than 100s...

party stared in the evnning around 7 and went back home around 4 a.m.
with in that time..

learn about a new pill (two days stright up... drop me an email if you want one :)
two guys almost had a fight
one guy vomited in the cab we went.
had to washe the cab (588588), (almost i vomited)
one guy broke one water tap,
went back in a 3- weeler