C#

MDX queries and T4 Templates

When I need to display data from a cube on a web page, I usually store the MDX query in a text file and make this file part of a resource file.  This allows me to store the MDX in a readable format. In the image below, I have two files in the App_GlobalResources folder.  The first [...]



Dynamic Forms in ASP.NET Part 3

In the first post in this series I looked at the database tables and procedures, in the second the classes that make up the question controls.  In this final part I will build the Survey class and show how to use it on a web page. Link to Part 1  Link to Part 2 You will recall [...]



Dynamic Forms in ASP.NET Part 2

In a previous post I started looking at a sample application that could dynamically create forms in ASP.NET and then store the user input into a database. In this post I am going to continue by looking at the classes used to generate the web controls. As I mentioned in the first post I took [...]



Stacking using statements

Within my C# code I use ‘using’ statement blocks all of the time to take advantage of the automatic disposal of objects. using (DataTable dt = new DataTable) { // Do Something } When you have quite a few of these statements inside each other, the code can look confusing (especially in longer methods). using [...]



SMS messages with C# and mobile dongle.

Create a console application and add the following code. using System; using System.IO.Ports; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; class Program { static void Main(string[] args) { using (SerialPort serialPort = new SerialPort()) { serialPort.PortName = “COM6″; serialPort.BaudRate = 9600; serialPort.Parity = Parity.None; serialPort.DataBits = 8; serialPort.StopBits = StopBits.One; serialPort.Handshake = Handshake.RequestToSend; serialPort.DtrEnabled = true; [...]



Content Panels & Update Triggers

An update panel trigger allows an asynchronous event be to raised from outside of the update panels content template. <asp:UpdatePanel runat=”server” id=”up1″> <ContentTemplate> <asp:Literal id=”ltTest” runat=”server”/> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID=”btnTest” EventName=”Click”/> </Triggers> </asp:UpdatePanel> <asp:Button runat=”server” id=”btnTest” Text=”Go” OnClick=”btnTest_Click”/> When using master pages and the update panel and trigger control are within different content areas the [...]



Using SQLSLR Part 3 – Table Valued Functions

Last week I built a web page that allowed users to view/amend their contact details stored in the company’s Active Directory (AD). When it came to writing the code to interface with AD I decided to use a SQLCLR library so that the requests would be executed in the context of the user account that [...]



Using SQLCLR Part 2 – A user defined function

In the first part of this series of blog entries I demonstrated creating a basic CLR component in C#.  In this blog I am going to create a CLR function that returns the lowest common denominator given two integers.  This is sometimes referred to as the lowest common multiple but I remember it from fractions in primary [...]



Using SQLCLR Part 1

Most articles I have seen on SQLCLR usually start with something like.. ‘create a new sql server database project in visual studio’ and while this is okay if you have one of the full editions of Visual Studio, it’s not a good start if you are using VS Express as most of the project templates [...]



Scripting with SMO

In SQL Server you can generate scripts of all the objects in a database using the management tools.  However this will only script one database at a time and it doesn’t remember the settings you have selected which would make running it again a lot easier. SMO or SQL Management Objects allows you to use a [...]