Skip to main content

Posts

Showing posts from September, 2011

Dynamic SQL Statements in SQL Server

Sometimes we need flexibility of using dynamic database name(s) in PL/SQL Statements. We might have an application where the database(s) are given an option in the drop downbox and the user can select any one. Based on the selection, another drop downbox shows all the tables in that database. In order to achieve the same, dynamic execution of sql statements can be used in SQL Server: declare @vDatabasename varchar (5 0 )          set @vDatabasename = 'Example' EXEC ( 'Select * from [' + @vDatabasename + '].sys.Tables' )

Delegates in VB.NET

Delegates in .NET Framework are equivalent to Function pointers in C and C++ language. Delegates helps in multithreaded application where one thread is accessing a UI element created by another thread. For e.g. the follwoing code will always return an error of type " Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on." Imports System.Threading Imports System.Reflection Public Class Form1     Private trd As Thread     Private Sub Button1_Click( ByVal sender As System. Object , ByVal e As System. EventArgs ) Handles Button1.Click         trd = New Thread ( AddressOf DoTask)         trd.IsBackground = True         trd.Start()     End Sub     Private Sub DoTask()         Dim i As Integer         i = 1         While i <= 1000             System. Console .WriteLine( "the value of i is:" + i.ToString())             i = i + 1             Thread .Sleep(1000)