Friday, August 26, 2011

Converting Timestamp value to string in SQL Server

Converting Timestamp value to string/varchar in SQL Server


Question :

   How to Convert SQL Server Timestamp Column to VARCHAR ?


Answer : 

SELECT CONVERT(VARCHAR(MAX), CONVERT(VARBINARY,Timestamp_Column_Name), 1) FROM Table 






How to Alter View / Table Function dynamically in sql server

How to Alter View / Table Function dynamically in sql server

Question :

Hi friends,



[ SQL SERVER 2008 ]



 I'm using UDDs ( User Defined DataType ) for my tables and created lot of views. Same UDD would refer muliple tables..


Now i changed my UDD in table by increasing size but its not reflecting in View.  if i alter that view then its reflecting..


so altering each view and table function manually is very difficult..


Answer :

              EXEC sp_refreshsqlmodule @View_Name/@Function_Name 


 

Getting Calling Class name in called class in .NET

Getting Calling Class name in called class in .NET

Question :

  I want to get the calling class name from Called class.
here calling class is Form1 and Called Class is Class1. 
I'm calling Test() function of Class1 from Form1, now in test() function i want to get the calling function that is Form1 .
Important thing is that I want to get without passing any parameters that is i don't want to change any signature of the function because its already completed projects,so this function has lot of references. so i want to get calling class name without changing / adding additional parameters..
ex :
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cls As New Class1
        cls.test()
    End Sub
End Class
Public Class Class1
    Public Sub test()
        '' HERE I WANT TO GET CALLING CLASS NAME i.e Form1
    End Sub
End Class

Answer :

Public Class Class1
    Public Sub test()
        '' HERE I WANT TO GET CALLING CLASS NAME i.e Form1

    Dim stackTractObject As New StackTrace

    Msgbox(stackTractObject.GetFrame(1).GetMethod.ReflectedType.Name)

    End Sub
End Class