Friday, December 22, 2006

All this time i though SET NONCOUNT ON is fater than OFF .. it is not .. there is a big dealy when you use ON.

check out
Performance Effects of NOCOUNT
http://www.sqlservercentral.com/columnists/dpoole/2751.asp

Monday, December 11, 2006

how to recover deleted or lost ldf file in SQL Server 2000 database ?

1. Backup the data (.mdf) file
2. EXEC sp_detach_db 'dbname' -- this will detach the database from the server
3. Restart SQL Server
The database may still be seen in enterprise manager, but just ignore it.
4. Create a new database with the same name or a different name. You will have to use a different physical file name, which is fine.
5. Stop SQL Server.
6. Rename the new data file that was created to something else (ex: add.bak to the end)
7. Rename the old data file that you want to restore to the name of the newly created file (the same name as the file you changed in the step above)
8. Start SQL Server
Now the db will still be suspect but you now have a log file.
9. Switch to emergency mode on the database. You do this by doing the following:
1. Right click on the database root node in Enterprise manager and bring up the properties.
2. Under the Server Settings tab, check of "Allow modifications to be made directly to the system catalogs".
3. click ok
4. Now go to the master database and open the sysdatabases table.
5. Find the suspected database in here and modify the status column, setting it to: 32768. This will put it into emergency mode.
6. stop then start sql server
10. Now here's the tricky part and I'm not sure how this will work on a single install, i was lucky enough to have SQL Server 2000 installed. But anyways, open up the Import and Export Data (DTS) program from the start menu. And you want to copy data from the old database to a brand new one. Just copy tables and views.

Wednesday, December 06, 2006

tempdb index planning

intersting artical on creation of indexes in tempDB

http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/tempdb_capacity_planning_index.mspx

Wednesday, November 29, 2006

teleporting ...

Last couple of days I was sick.. sick very badly.. and I was @ home with out doing any thing.. so most of my time i spent infont of the T.V..

there was an intersting program on CNN about the Next Genration Human Transpotation ?? they were taking about various things such as teleporting?.. one woemn was there said it is impossible. That is the same thing we though when ppl said ppl are going to fly,,? isn;t it..

So i though about teleporting.. how to do it? Well if we can compress our selfs and defined in 1's and 0's the we should be able to transport via a cable isn't it ? that is the only way i can think of, or may be i was out of my mind due to sickness

Wednesday, November 22, 2006

Gmail Maps Viewing (GMaps)

Last couple of days i was doing a re-search on GMaps. it;s to enable the routing maps on the windows descktop applicate it self.

only think that you have to do is to pass the correct argements.. But still I cound;t find how to use the birdview.. if you know let me know..

Destination Address
+++++++++++++++

Its address is, roughly, 2233 S. Columbus Blvd.
http://maps.google.com/?q=2233+s+columbus+blvd+philadelphia&z=1

Location wise
+++++++++
I can be more accurate with latitude and longitude. 39.918 N, 75.135W. So this link is even better:
http://maps.google.com/?sll=39.918,-75.136

Parameters are there besides "q" (the regular Google query parameter), "z" (zoomlevel) and "sll" (latitude and longitude)

From : To
+++++++

"q" param denotes "from" in front of the first, and "to" in front of the second, and it will give you the directions between the two addresses.

Example: http://maps.google.com/maps?q=from+2233+s+columbus+blvd+philadelphia+to+1600+pennsylvania+ave,+washington,+dc&z=8

Thursday, November 16, 2006

Two greate Index Build strategys !

Index Build strategy in SQL Server - Introduction (I)
http://blogs.msdn.com/sqlqueryprocessing/archive/2006/11/08/index-build-strategy-in-sql-server-introduction-i.aspx


Index Build strategy in SQL Server - Introduction (II)
http://blogs.msdn.com/sqlqueryprocessing/archive/2006/11/09/index-build-strategy-in-sql-server-introduction-ii.aspx

Thursday, November 09, 2006

DataGrid with Excel Copy and Paste

I coudn''t blog last couple of days due to my busy schedule. So I am back !!!! Y'day and today i was tring to create a control with the excel copy and past it in the datagrid type of a comtrol. first it was a disster, with the help of winformsfaq site i managed to do it. I have paste the full code in the blog. i hope one day it will help you 2

'--------------------------------------------------------------------------------------------------
' Waha gini awelana sului
'------------------------------------------------------------------------------------------

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.IO

Public Delegate Sub DataGridSelectionChangingEventHandler(ByVal sender As Object, ByVal e As DataGridSelectionChangingEventArgs)


Public Class iOMSelectionDataGrid
Inherits DataGrid

'fired when a selection is about to change
Public Event SelectionChanging As DataGridSelectionChangingEventHandler

'(top,left,bottom,right) of selection
Private _selectedRange As GridRange

'used in drawing
Private _selectionRectangle As Rectangle
Private _clipRectangle As Rectangle

'used to record row-col of click
Private _mouseDownRow As Integer
Private _mouseDownCol As Integer
Private _mouseUpRow As Integer
Private _mouseUpCol As Integer

'used in autoscroll
Private lastMoveHorz As Boolean

Friend WithEvents ContextPasteMenu As System.Windows.Forms.ContextMenu
Friend WithEvents MenuItemPaste As System.Windows.Forms.MenuItem
Friend WithEvents MenuItemClear As System.Windows.Forms.MenuItem

Public Sub New()
_selectedRange = New GridRange
_clipRectangle = Rectangle.Empty

'used to redraw selection during a scroll
AddHandler Me.Scroll, AddressOf HandleScroll

'used to get a clipping rectange for the initial display
AddHandler Me.Paint, AddressOf FirstPaint

Me.ContextPasteMenu = New System.Windows.Forms.ContextMenu
Me.MenuItemPaste = New System.Windows.Forms.MenuItem
Me.MenuItemClear = New System.Windows.Forms.MenuItem
'
'ContextPasteMenu
'
Me.ContextPasteMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItemClear, Me.MenuItemPaste})
'
'MenuItemPaste
'
Me.MenuItemPaste.Index = 0
Me.MenuItemPaste.Text = "&Paste"
'
'MenuItemClear
'
Me.MenuItemClear.Index = 1
Me.MenuItemClear.Text = "&Clear"
'
'set up double buffering to minimize flashing during draws
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
End Sub 'New


#Region "Paint & Scroll Event Handlers"
Private Sub FirstPaint(ByVal sender As Object, ByVal e As PaintEventArgs)
'used to mark the size of original clientsize
RemoveHandler Me.Paint, AddressOf FirstPaint
If Not Me.DesignMode Then
_clipRectangle = Me.GetCellBounds(0, 0)
_clipRectangle.Height = Me.Height - _clipRectangle.Y - SystemInformation.HorizontalScrollBarHeight
_clipRectangle.Width = Me.Width - _clipRectangle.X - SystemInformation.VerticalScrollBarWidth
End If
End Sub 'FirstPaint


'helper method that gets the left column from knowing the initial cliprectangle
Public Function LeftColumn() As Integer
Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(_clipRectangle.X, _clipRectangle.Y))
Return hti.Column
End Function 'LeftColumn

Private Sub HandleScroll(ByVal sender As Object, ByVal e As EventArgs)
DrawRange(True)
End Sub 'HandleScroll
#End Region

#Region "Selected Range property"

Public Property SelectedRange() As GridRange
Get
Return _selectedRange
End Get
Set(ByVal Value As GridRange)
'If Not (SelectionChanging Is Nothing) Then
Dim e As New DataGridSelectionChangingEventArgs(_selectedRange, Value)
RaiseEvent SelectionChanging(Me, e)
If e.Canceled Then
Return
End If
'End If
_selectedRange = Value
End Set
End Property

#End Region

#Region "mouse events that handle making selections"

Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
'remember the initial click
If e.Button = MouseButtons.Left Then
Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))
_mouseDownRow = hti.Row
_mouseDownCol = hti.Column
_mouseUpRow = _mouseDownRow
_mouseUpCol = _mouseDownCol

'clear any existing selection
SelectedRange.Clear()
DrawRange(False)
ElseIf e.Button = MouseButtons.Right Then
'// Dispaly the menu on right click
ContextPasteMenu.Show(Me, New Point(e.X, e.Y))
End If

End Sub 'OnMouseDown


Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseMove(e)

If e.Button = MouseButtons.Left Then
Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

Select Case hti.Type
'move to a visible cell with no scrolling
Case HitTestType.Cell
If hti.Column <> Me._mouseUpCol OrElse hti.Row <> Me._mouseUpRow Then
lastMoveHorz = Me._mouseUpCol <> hti.Column

DrawRange(False)
Me._mouseUpCol = hti.Column
Me._mouseUpRow = hti.Row
SelectedRange = New GridRange(Me._mouseUpRow, Me._mouseUpCol, Me._mouseDownRow, Me._mouseDownCol)
DrawRange(True)
End If



Case HitTestType.ColumnHeader
If Me._mouseDownRow = -1 Then
Exit Select
End If
If Me.VertScrollBar.Value > 0 Then
Me.VertScrollBar.Value = Me.VertScrollBar.Value - 1
Me.CurrentRowIndex = Me.VertScrollBar.Value

Me._mouseUpCol = hti.Column
Me._mouseUpRow = Me._mouseUpRow - 1
SelectedRange = New GridRange(Me._mouseUpRow, Me._mouseUpCol, Me._mouseDownRow, Me._mouseDownCol)
DrawRange(True)
End If 'this.Invalidate();
Case HitTestType.RowHeader
If (True) Then
If Me._mouseDownCol = -1 Then
Exit Select
End If
Dim r As Rectangle = Me.GetCellBounds(0, Me._mouseUpCol)
If Me.HorizScrollBar.Value >= r.Width Then
Me.HorizScrollBar.Value -= r.Width
Me._mouseUpCol = Me._mouseUpCol - 1
Me.CurrentCell = New DataGridCell(Me.CurrentRowIndex, Me._mouseUpCol)

Me._mouseUpRow = hti.Row
SelectedRange = New GridRange(Me._mouseUpRow, Me._mouseUpCol, Me._mouseDownRow, Me._mouseDownCol)
DrawRange(True)
End If 'this.Invalidate();
End If
Case HitTestType.None
'Console.WriteLine("HitTestType.None");
If lastMoveHorz Then
Console.WriteLine("lastMoveHorz")
If Me._mouseUpCol < rectangle =" Me.GetCellBounds(0," _mouseupcol =" Me._mouseUpCol" currentcell =" New"> -1 Then
Me._mouseUpRow = hti.Row
End If
SelectedRange = New GridRange(Me._mouseUpRow, Me._mouseUpCol, Me._mouseDownRow, Me._mouseDownCol)
DrawRange(True)
End If
End If 'this.Invalidate();
Else
If Me._mouseUpRow < _mouseuprow =" Me._mouseUpRow"> 0 Then
Me._mouseUpCol = hti.Column
End If
Me.CurrentCell = New DataGridCell(Me._mouseUpRow, Me._mouseUpCol)

SelectedRange = New GridRange(Me._mouseUpRow, Me._mouseUpCol, Me._mouseDownRow, Me._mouseDownCol)
DrawRange(True)
End If 'this.Invalidate();
End If

End Select
End If
End Sub 'OnMouseMove


Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
'if normal click clear things & click
If Me._mouseUpCol = Me._mouseDownCol AndAlso Me._mouseUpRow = Me._mouseDownRow Then
DrawRange(False)
_selectionRectangle = Rectangle.Empty
MyBase.OnMouseDown(e)
MyBase.OnMouseUp(e)
End If
End Sub 'OnMouseUp


#End Region

#Region "Drawing Code"

Private Sub DrawRange(ByVal showRange As Boolean)
'if removing selection just redraw
If Not showRange Then
_selectionRectangle = Rectangle.Empty
Me.Invalidate()

Return
End If

If SelectedRange.Left < _selectionrectangle =" Rectangle.Empty" rectangle =" Me.GetCellBounds(SelectedRange.Top," rectangle =" Me.GetCellBounds(SelectedRange.Bottom," x =" rect.Left" w =" rect1.Left" x =" rect1.Left" w =" rect.Left" y =" rect.Top" h =" rect1.Top" y =" rect1.Top" h =" rect.Top" _selectionrectangle =" New" height =" Me.Height" width =" Me.Width" datatable =" getExcelCopiedCells()" datatable =" CType(MyBase.DataSource," integer =" SelectedRange.Top" integer =" SelectedRange.Bottom" integer =" (SelectedRange.Bottom" integer =" SelectedRange.Left" integer =" SelectedRange.Right" integer =" (SelectedRange.Right" integer =" SelectedTop" integer =" SelectedLeft" selectedvalue =" Me(currentRowPos," selectedvalue = "NI" selectedvalue = "NP" selectedvalue = "NC" selectedvalue = "NF" selectedvalue = "ND" selectedvalue = "NT" selectedvalue = "NS" idataobject =" Clipboard.GetDataObject()" char =" {"> 0)
'Array to hold the split data for each row
Dim arrSplitData As Array

'Multipurpose Loop Counter
Dim iLoopCounter As Integer = 0

'Read a line of data from the StreamReader object
sFormattedData = srReadExcel.ReadLine()

'Split the string contents into an array
arrSplitData = sFormattedData.Split(charDelimiterArray)

If tblExcel2WinData.Columns.Count <= 0 Then
For iLoopCounter = 0 To arrSplitData.GetUpperBound(0)
tblExcel2WinData.Columns.Add()
Next
iLoopCounter = 0
End If

'Row to hold a single row of the Excel Data
Dim rowNew As DataRow
rowNew = tblExcel2WinData.NewRow()


For iLoopCounter = 0 To arrSplitData.GetUpperBound(0)
rowNew(iLoopCounter) = arrSplitData.GetValue(iLoopCounter)
Next
iLoopCounter = 0

'Add the row back to the DataTable
tblExcel2WinData.Rows.Add(rowNew)

rowNew = Nothing
End While

'Close the StreamReader object
srReadExcel.Close()

'Bind the data to the DataGrid
Return tblExcel2WinData
Else
MsgBox("Clipboard data does not seem to be copied from Excel!", MsgBoxStyle.Information)
Return Nothing
End If
Else
MsgBox("Clipboard is empty!", MsgBoxStyle.Information)
Return Nothing
End If

Catch exp As Exception
MsgBox(exp.Message, MsgBoxStyle.Information)
Return Nothing
End Try

End Function

Private Sub MenuItemClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItemClear.Click


Dim SelectedTop As Integer = SelectedRange.Top
Dim SelectedBottom As Integer = SelectedRange.Bottom
Dim SelectedTopToBottom As Integer = (SelectedRange.Bottom - SelectedRange.Top) + 1
Dim SelectedLeft As Integer = SelectedRange.Left
Dim SelectedRight As Integer = SelectedRange.Right
Dim SelectedLeftToRight As Integer = (SelectedRange.Right - SelectedRange.Left) + 1
Dim selectedValue As String

'// Row Navigation
For currentRowPos As Integer = SelectedTop To SelectedBottom

'//Column Navigation
For CurrentColPos As Integer = SelectedLeft To SelectedRight

Try

selectedValue = Me(currentRowPos, CurrentColPos)

If selectedValue = "NI" OrElse selectedValue = "NP" OrElse selectedValue = "NC" OrElse selectedValue = "NF" OrElse selectedValue = "ND" OrElse selectedValue = "NT" OrElse selectedValue = "NS" Then
'// Color cells do nothing
Else
Me(currentRowPos, CurrentColPos) = ""
End If

Catch ex As Exception
End Try

Next CurrentColPos

Next currentRowPos


End Sub

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

Dim cellCurrent As DataGridCell
Dim curentCellValue As String

Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104

If msg.Msg = WM_KEYDOWN Or msg.Msg = WM_SYSKEYDOWN Then
Select Case keyData
Case Keys.Control Or Keys.V
Call MenuItemPaste_Click(Nothing, Nothing)
End Select
End If

Return MyBase.ProcessCmdKey(msg, keyData)

End Function


End Class 'SelectionDataGrid '


#Region "GridRange class implementation"
'----^--- Pre-processor directives not translated

Public Class GridRange
Private _top As Integer
Private _left As Integer
Private _bottom As Integer
Private _right As Integer


Public Sub New()
_top = -1
_left = -1
_bottom = -1
_right = -1
End Sub 'New


Public Sub New(ByVal t As Integer, ByVal l As Integer, ByVal b As Integer, ByVal r As Integer)
_top = Math.Min(t, b)
_left = Math.Min(l, r)
_bottom = Math.Max(t, b)
_right = Math.Max(l, r)
End Sub 'New


Public Property Top() As Integer
Get
Return _top
End Get
Set(ByVal Value As Integer)
_top = Value
End Set
End Property

Public Property Bottom() As Integer
Get
Return _bottom
End Get
Set(ByVal Value As Integer)
_bottom = Value
End Set
End Property

Public Property Left() As Integer
Get
Return _left
End Get
Set(ByVal Value As Integer)
_left = Value
End Set
End Property

Public Property Right() As Integer
Get
Return _right
End Get
Set(ByVal Value As Integer)
_right = Value
End Set
End Property

Public Sub Clear()
Me.Bottom = -1
Me.Top = -1
Me.Left = -1
Me.Right = -1
End Sub 'Clear


Public Overrides Function ToString() As String
Return "TopLeft:" + Me.Top.ToString() + "," + Me.Left.ToString() + " BottomRight:" + Me.Bottom.ToString() + "," + Me.Right.ToString()
End Function 'ToString
End Class 'GridRange



#End Region

#Region "SelectionChangingEvent class implementation"


Public Class DataGridSelectionChangingEventArgs
Inherits EventArgs
Private _oldRange As GridRange
Private _newRange As GridRange
Private _canceled As Boolean


Public Sub New(ByVal oldValue As GridRange, ByVal newValue As GridRange)
_oldRange = New GridRange(oldValue.Top, oldValue.Left, oldValue.Bottom, oldValue.Right)
_newRange = New GridRange(newValue.Top, newValue.Left, newValue.Bottom, newValue.Right)
_canceled = False
End Sub 'New


Public Property Canceled() As Boolean
Get
Return _canceled
End Get
Set(ByVal Value As Boolean)
_canceled = Value
End Set
End Property

Public Property OldRange() As GridRange
Get
Return _oldRange
End Get
Set(ByVal Value As GridRange)
_oldRange.Bottom = Value.Bottom
_oldRange.Top = Value.Top
_oldRange.Left = Value.Left
_oldRange.Right = Value.Right
End Set
End Property

Public Property NewRange() As GridRange
Get
Return _newRange
End Get
Set(ByVal Value As GridRange)
_newRange.Bottom = Value.Bottom
_newRange.Top = Value.Top
_newRange.Left = Value.Left
_newRange.Right = Value.Right
End Set
End Property
End Class 'DataGridSelectionChangingEventArgs
#End Region

Tuesday, October 31, 2006

Fine Tuning your Database Design in SQL 2005

today i found a nice artical on Fine Tuning your Database Design in SQL 2005

check it out @
http://www.simple-talk.com/sql/sql-server-2005/fine-tuning-your-database-design-in-sql-2005/

Friday, October 27, 2006

PIVOT dynamic column list

There was an intersting question posted on the .NET forum yday. it was about dynamically changing column list. In PIVOT you have to specify the output column list manually?
is it a bug ??

I found to achive it by doing hours of trying ....

DECLARE @colList VARCHAR(1024)

SELECT @colList = COALESCE(@colList + ',', '') + Subject FROM
(
SELECT DISTINCT '[' + Subject + ']' AS Subject
FROM StudentMarks
) AS StudentMarksColList

--get the column in the array format [maths], [science] ect ..
SELECT @colList


EXEC('SELECT * FROM StudentMarks
PIVOT
(
SUM(Marks)
FOR Subject
IN ('+ @colList +')
)AS p')

Wednesday, October 25, 2006

SQL Articals

Two greate articals by Ron Talmage


http://www.code-magazine.com/Article.aspx?quickid=060063
http://www.code-magazine.com/Article.aspx?quickid=060093

Wednesday, October 18, 2006

BCS Exam

I was buys last couple of days studing for the BCS exams .. I took 2 papers which are Information Systems and Core Paper. I nailed the BCS Information systems paper.. it was soo easy.. but the core paper was taugh.. I haven't given up the hopes still on it.

Wednesday, October 11, 2006

What's The Resolution?

should read this if you want to know what is dah above topic is all about..

http://www.code-magazine.com/Article.aspx?quickid=060083

Monday, October 09, 2006

Inserting way to insert data to the tabase

I found this code while surfing the web today. Concept is very intersting due to couple of resions.

1. Reduce round trips
2. cocurrency handing
3. More control over the logic
4. it is clear.. !!!!


create proc dbo.Item_Add_toOrderList
(
@orderNumber char(20)
@itemNumber char(20)
@processedBy varchar(64) = null
)
as
declare @errorNumber

-- Test processedBy
if (@processedBy is null) set @processedBy = system_user

-- Transaction
begin tran

-- Test orderNumber (makre sure an appropriate order exists)
if not exists(select OrderID from dbo.Order where (OrderNumber =
@orderNumber))
begin
rollback tran
raiserror ('Item Add failed: orderNumber %s unknown.', 16, 1,
@orderNumber)
return -1
/*
This is the first point at which the transaction will be rolled back if one
of the parameters is erroneous.
*/
end

-- Initialize errorNumber
set @errorNumber = 0

insert dbo.Item
(
orderNumber
,itemNumber
,processedBy
,processedOn
)
select @orderNumber as orderNumber
,@itemNumber as itemNumber
,@processedBy as processedBy
,getdate() as processedOn

-- store current error code
set @errorNumber = @@error

if (@errorNumber != 0)
begin
rollback tran
raiserror ('Item Add failed: an error has occured.', 16, 1)
return @errorNumber
/* Here the transaction is rolled-back if an error occured at insert. */
end
else
begin
commit tran
return 0
/* If no error present transaction is committed. */
end
go

Sunday, October 08, 2006

Life

Y'day I was thinking to my self what is the meanning of life??? well have you ever though about it? I bet you would have unless you are not living in a shit whole like me.

We all have a child hood that we can't forget or that we are trying to forget. Then we try to find a job that we can really enjoy, suddenly we get sick of it and you wish to go back to old that .. fun days!!! . And so on you get married and have kids and you watch how they grow up?.

finally when you look bouth you see that parents, brothers, relatives all are passed away.. And now it is your turn.. suddenly we are feeling the frear to die..

And one fine day you die.. That is what we all do ? have you ever though of doing some thing apart from that ?? those are the very basic things that common to all of us, We have to brake that chain... but how???

think who do whant to be in life that you will engoy.. otherwise one day we will feel that we have forgoten to enjoy our lifes so enjoy!

besides, if you figure out a way please let me know coz still i am thinking ....!

Thursday, October 05, 2006

Improve Performance with SQL 2005 Covering Index Enhancements

some thing that I have been expecting...

Improve Performance with SQL 2005 Covering Index Enhancements
http://www.mssqltips.com/tip.asp?tip1078

http://msdn2.microsoft.com/en-us/library/ms190806.aspx

Wednesday, October 04, 2006

Passing parameters to SPs

I have head lot of people are asking how to pass paramerts to a stored proc ?? this is how i like to do

<args>

<customerid>12</customerid>

</args>

Friday, September 29, 2006

Your Own Serviced Layer ?

Have you ever though of writting a serviced layer? well I just did.. :) I wrote a small example also .. It quit intersting... It easy if you have constat attributes in your project, if not you will be in a sup ..

I have posted the code here..


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim myCars As New Cars
myCars.Add(New Car("SDSDSD"))

For Each b As Car In myCars
MsgBox(b.Name)
Next






End Sub
End Class

Public Class Car

Private mName As String

Public Sub New(ByVal CarName As String)
mName = CarName
End Sub

Public Property Name() As String
Get
Return mName
End Get

Set(ByVal Value As String)
mName = Value
End Set
End Property

End Class

Public Class Cars
Implements IEnumerable

Private mList As New ArrayList

Public Sub Add(ByVal bk As Car)
mList.Add(bk)
End Sub

Default Public ReadOnly Property List(ByVal index As Integer) As Car
Get
Return DirectCast(mList(index), Car)
End Get
End Property

Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
Return New CarsEnumerator(mList)
End Function

Class CarsEnumerator
Implements IEnumerator

Private index As Integer = -1

Private mList As ArrayList

Friend Sub New(ByVal list As ArrayList)
mList = list
End Sub

Public ReadOnly Property Current() As Object Implements System.Collections.IEnumerator.Current
Get
Return mList(index)
End Get
End Property

Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext
If index < mList.Count - 1 Then
index += 1
Return True
Else
Return False
End If
End Function

Public Sub Reset() Implements System.Collections.IEnumerator.Reset
index = 0
End Sub
End Class
End Class

Wednesday, September 06, 2006

Tuesday, September 05, 2006

Conditional Debugging ?

 

Some thimes you have to hide some errors in the debug versions and display a nice customized message in da release versions. I found this intersting artical which explains the conditional debugging. check it out at

 

http://blogs.vandamme.com/development/archives/200...

Monday, September 04, 2006

Here is My C# Resources

 

 

Helpful C# Resources

I compiled a list of some of resources for people just starting out with C# and .NET. If you have any that you recommend, please share!

http://codeproject.com – tons of free projects available for download. This I a great resource for even the most experience programmers. There are pretty much projects detailing how to do anything (especially in windows desktop development)

http://msdn.microsoft.com/vcsharp – the official C# website at Microsoft. There are a lot of good downloads here for code snippets and sample projects. There are also links to the Microsoft community and support forums. Definitely worth a bookmark.

http://msdn.microsoft.com/vcsharp/downloads/2005 – lots of free source code to get started.

http://www.c-sharpcorner.com – another great site similar to codeproject which catalogs many thousands of lines of free code and tutorials.

http://www.csharp-station.com – great beginner tutorials for C# and ADO.NET

http://www.csharphelp.com – more code snippets than full projects but very helpful for learning quick things and fixing bugs

http://www.csharpfriends.com – another huge resource of code and tutorials

http://en.wikipedia.org/wiki/CSharpprogramming_language – basic tutorial and a lot of good links at the bottom under References.

http://blogs.msdn.com/csharpfaq – C# FAQ blog by Microsoft

http://csharp-source.net – C# resources (no code)

Pro C# 2005 and the .NET 2.0 Platform, Third Edition (Hardcover) http://www.amazon.com/gp/product/1590594193/sr=8-3/qid=1148997675/ref=pdbbs3/102-1539900-6421701?%5Fencoding=UTF8

Programming Microsoft Visual C# 2005: The Language (Paperback) http://www.amazon.com/gp/product/0735621810/sr=8-6/qid=1148997675/ref=pdbbs6/102-1539900-6421701?%5Fencoding=UTF8

Pro ADO.NET 2.0 (Expert’s Voice) (Paperback) http://www.amazon.com/gp/product/1590595122/qid=1148997798/sr=2-1/ref=pdbbsb21/102-1539900-6421701?s=books&v=glance&n=283155

Programming Microsoft ASP.NET 2.0 Core Reference (Paperback) http://www.amazon.com/gp/product/0735621764/qid=1148997822/sr=2-2/ref=pdbbsb22/102

Wednesday, August 30, 2006

Executing SQL Scripts ?

 

Most of the deverlopers has this question, how to create the dev database using a wizard, I bevelie the easyest way out is to use the osql,

execute this in the command prompt.

osql /S (local) /U sa /O sa /i C:\script.sql

 

And I found this intersting artical about how to handle SQL failover functionalities with .NET,

 

http://www.doingitwith.net/2006/08/getting-warmer-...

Monday, August 28, 2006

USB Dunper

USBDumper is a cute little utility that silently copies the contents of an inserted USB drive onto the PC. Try it out here ..

 

http://www.schneier.com/blog/archives/2006/08/usbd...

 

 

RAM DRIVE ?

have you tried this yet ? cool

http://sqlblogcasts.com/blogs/tonyrogerson/archive...

Thursday, August 24, 2006

WinPOS

I spend y'day and today trying to implement promotion and loyalty funcanaliity to our winPOS. It was not that easy when I discuss the funcations, but when i put it in to a paper and wrote down the logic how to implelemnt it wasn't that much. prob i was thinking too much and strees out.

 

I found a very intersting artical today at SQLServerCentral check it out

http://www.sqlservercentral.com/columnists/sjones/...

 

SP to Script SQL Server tables ..

 

 

/********************************************************/
/****** Object:  Stored Procedure dbo.proc_genscript    
/******Script Date: 5/8/2003 11:06:52 AM ******/
/****** Created By:    Shailesh Khanal ******/
/********************************************************/
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[sp_ScriptObject]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[sp_ScriptObject]
GO
/* This procedure will script out one object so it can be recreated using a T-SQL Script
Modified 11/18/04 to handle Alerts and Operators
Usage:
exec sp_ScriptObject 
       @ServerName = 'Server Name', 
       @DBName = 'Database Name', 
       @ObjectName = 'Object Name to generate script for', 
       @ObjectType = 'Object Type', 
       @TableName = 'Parent table name for index and trigger',
       @ScriptFile = 'File name to save the script'
*/
CREATE PROCEDURE sp_ScriptObject 
@ServerName VARCHAR(30), 
@DBName VARCHAR(30), 
@ObjectName VARCHAR(256), 
@ObjectType VARCHAR(10), 
@TableName VARCHAR(50),
@ScriptFile VARCHAR(256)
AS
DECLARE @CmdStr VARCHAR(256)
DECLARE @object INT
DECLARE @hr INT
SET NOCOUNT ON
SET @CmdStr = 'Connect('+@ServerName+')'
EXEC @hr = sp_OACreate 'SQLDMO.SQLServer', @object OUT
--Comment out for standard login
EXEC @hr = sp_OASetProperty @object, 'LoginSecure', TRUE
/* Uncomment for Standard Login
EXEC @hr = sp_OASetProperty @object, 'Login', 'sa'
EXEC @hr = sp_OASetProperty @object, 'password', 'sapassword'
*/
EXEC @hr = sp_OAMethod @object,@CmdStr
SET @CmdStr = 
CASE @ObjectType
WHEN 'Database' THEN 'Databases("' 
WHEN 'Procedure' THEN 'Databases("' + @DBName + '").StoredProcedures("'
WHEN 'View'     THEN 'Databases("' + @DBName + '").Views("'
WHEN 'Table'    THEN 'Databases("' + @DBName + '").Tables("'
WHEN 'Index'    THEN 'Databases("' + @DBName + '").Tables("' + @TableName + '").Indexes("'
WHEN 'Trigger'  THEN 'Databases("' + @DBName + '").Tables("' + @TableName + '").Triggers("'
WHEN 'Key'      THEN 'Databases("' + @DBName + '").Tables("' + @TableName + '").Keys("'
WHEN 'Check'    THEN 'Databases("' + @DBName + '").Tables("' + @TableName + '").Checks("'
WHEN 'Job'      THEN 'Jobserver.Jobs("'
WHEN 'Alert'    THEN 'Jobserver.Alerts("'
WHEN 'Operator' THEN 'Jobserver.Operators("'
END
SET @CmdStr = @CmdStr + @ObjectName + '").Script(5,"' + @ScriptFile + '")'
EXEC @hr = sp_OAMethod @object, @CmdStr
EXEC @hr = sp_OADestroy @object
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

Monday, August 21, 2006

Heavy Rainning

 

it was rainning in dah mornning as well as y'day whole day. I spent more than 10 hours with the laptop since i can't do any thing more than that.

 

there is a good atrical published @ http://www.sqlservercentral.com/columnists/dpoole/... for dah .NET Enterprise Library, i think it is a very baisc document that ever one can undestand, even me :)

Friday, August 18, 2006

Wednesday, February 22, 2006

DataGrid's DataGridTextBoxColumn

last couple of day i was tring to write a custom grid for retailigence. Every time when u want the old text box on a cell you have to create a DataGridTextBoxColumn custom data column. functionalliy of that grid is very limited. can't color, lots of limitations.