Archive for the ‘Technology’ Category

.Net Blocking websites

Sunday, July 27th, 2008

Think in the lines of Parental control application where we need to block certain websites from being accessed. To make it harder, this will be a Windows application where user can configure the sites to be blocked and unblocked.

Let’s start thinking of what we can do to achieve this.
(more…)

WPF Multiline Textbox

Wednesday, June 11th, 2008

The following code snippet demonstrates how to have a multiline WPF TextBox.

(more…)

WPF Setting Grid row and column number for a control being added to Grid

Saturday, June 7th, 2008

In normal case we generally add our controls to the WPF Grid in XAML setting the Row and Column value. If you want to add a control to the Grid at runtime from Code-behind, the way to do it will be,

yourGrid.Children.Add(yourControl);

(more…)

WPF Multitrigger

Thursday, May 15th, 2008

This article discusses and demonstrates the implementation of a trigger in WPF which has multiple conditions.

Triggers in WPF are very important and handy features. Triggers and styles add to WPF’s bag a rich set of functionality. Triggers are like event handlers which we define in XAML’s DateTemplates and styles.Triggers allow us to define several Setter elements in a style. The trigger includes a condition, and when that condition is true, the Setters defined in the trigger will be applied. When the condition is false, the Setters are ignored.

Here is a sample trigger,

< Style.Triggers >
    < Trigger Property="IsEnabled" Value="False" >
      < Setter Property="Visibility" Value="Collapsed" / >
    < /Trigger >
< /Style.Triggers >

The above example demonstrates a Style trigger which fires when the IsEnabled property is false. The resulting controls Visibility property will be set to Collapsed.

Moving ahead, what if our condition is based on multiple criteria? Here comes the use of MultiTriggers.

Here is a sample Multi-Trigger,

< MultiTrigger >
      < MultiTrigger.Conditions >
        < Condition Property="Content" Value="a" / >
        < Condition Property="IsMouseOver" Value="True" / >
      < /MultiTrigger.Conditions >
      < Setter Property="Visibility" Value="Collapsed" / >
< /MultiTrigger >

The above trigger will fire when Content has a value of “a” and mouse is over the control.

Have fun.

C# Conditional breakpoints - Debugging a thread

Thursday, April 3rd, 2008

One of the cool feature of VS is the ability to set conditional breakpoints i.e. setting a breakpoints which hit based on a condition. When the condition is True the breakpoint will hit or else it won’t.
(more…)

WPF Timer

Wednesday, March 26th, 2008

This article discusses the WPF DispatcherTimer.

Most of us are from a background of C# (or VB.Net). You must have some point of time come across a scenario for performing a repetitive GUI operation after certain period of time. The solution in most cases has been the WinForm’s Timer.

What about WPF ? Does it have a Timer ?
(more…)

Find if database, table or stored procedure exists using C#

Saturday, February 23rd, 2008

There is a cool list of MetaData functions present in SQL server. I will be discussing one of them - object_id

Often we need to check if the Database is present and if it not then we need to create a new one. The most common answer to this is, try to connect to the Db and if the connection fails/throws an exception then the database does not exist. Do you think it is correct ?
(more…)

WPF Formatting in XAML Binding

Wednesday, December 5th, 2007

Ever wondered how to format a string in a XAML binding ?
This following code snippet demonstrates how to format a string in a databinding.
(more…)

Accessing multiple servers in a single SQL query

Friday, October 26th, 2007

The following SQL query demonstrates how to query between two SQL servers in the same query.

Here is the sample. The query demonstrate a join between two tables in different SQL server instances,

SELECT * FROM anotherServer.DataBaseName.dbo.TableName table1
inner join tableName2 tbale2 on  table2.Id = table1.Id

anotherServer - this is name of the instance of the second SQL sever
DataBaseName - this is the Database name in which the table resides on the second SQL Server instance
TableName - Name of the table in the second SQL Server instance

To make this possible, it is necessary to link the second SQL Server instance to the first one.
To link the SQL Servers there is a inbuilt stored proc named ’sp_addlinkedserver’.

Here is a sample to link to an SQL server instance named ‘anotherServer’,

EXEC    sp_addlinkedserver
  @server='machineName',
  @srvproduct='',
  @provider='SQLOLEDB',
  @datasrc='anotherServer',
  @catalog ='DatabaseName'

You will need to link the servers before you can run queries accessing a different server.

It might also be needed to add login for the server linking. For this, we will need to add a login using sp_addlinkedsrvlogin

Here is a sample way,

EXEC sp_addlinkedsrvlogin
  'anotherServer',
  'false',
   NULL,
  'Username',
  'Password'

Have fun.

.Net Rounding to nearest 10

Wednesday, September 5th, 2007

The following code demonstrates how to round a number to the nearest 10 or 100 or 100 or etc..

(more…)