## Lookups in PowerPivot Calculated Columns – Using the RELATED Function

In my previous post we looked at how Calculated Columns work in PowerPivot. One limitation you may have noticed though was all of the calculations were done using values in that individual table. What if you wanted to lookup a value in second table, based on a value in the first table, and return a value from that second table. Yes Virginia, not only is there a Santa Clause but there’s also an answer for us in PowerPivot’s RELATED function.

In addition to the standard Excel functions, PowerPivot provides a set of its own functions for working with its data. These new functions are collectively known as Data Analysis eXpressions, or DAX for short. By now you’ve probably guessed that the first function from the DAX toolbox you’ll want to learn is the RELATED function.

Let’s start with the same Excel 2010 workbook we had at the end of the lesson Combining Data from Multiple Sources in PowerPivot. If you recall we had imported data from the AdventureWorksLT2008 database. To that we added data the CountryInfo table, which we’d typed in to an Excel spreadsheet.

At the time we used this to get the CountryAbbr column, and you may have wondered why we also included a DiscountRate column. It’s this lesson where this DiscountRate will come in to play.

If you recall from that post, we used PowerPivot’s Manage Relationships feature to create a link that ultimately connected the SalesOrderDetail table to the CountryInfo table. This groundwork enables us to lookup values very easily. Here is a simple example. Go to the Add Column column of SalesOrderDetail and enter this formula into the fx area:

=RELATED(‘CountryInfo'[CountryAbbr])

When PowerPivot gets done, the abbreviation for each country to be shipped to appears in this column. This can be used to “flatten out” some of your data. However it’s much more useful when used as part of a calculation. Delete the column we just added (right click on the column header and pick Delete Column from the menu).

Looking in the CountryInfo table we see the DiscountRate. A value of 0.04 means our US customers get a discount of 4% off their LineTotal. So in our SalesOrderDetail table we want to take the LineTotal and calculate a new value based on the rate, which is stored in the CountryInfo table. Simple enough using the PowerPivot RELATED function.

=[LineTotal] * (1 – RELATED(‘CountryInfo'[DiscountRate]))

This is fairly simple math, we take the DiscountRate from CountryInfo (for US, 0.04) and subtract from 1 giving us 0.96, or 96%. This is then multiplied by the LineTotal giving us our new discounted LineTotal amount, which I renamed to DiscountedLineTotal.

Hopefully these simple examples will give you a glimpse of the immense power RELATED offers. It will allow you to combine data from multiple tables to create in-depth analysis that previously required a specialist in Business Intelligence to create.

## TechMixer University – SSIS for Developers

In addition to help recruit speakers, I also had the privilege of speaking at TechMixer University 2009.

The slide deck and main demo can be found at my Code Gallery site:

https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=SSISForDevs&ReleaseId=2883

The calling of SSIS from .Net demo can be found at:

http://code.msdn.microsoft.com/ssisfromnet

Thanks to everyone who attended TechMixer University. I look forward to seeing you next year!

In the previous entry we covered how to upload a file to SQL Server using the FILESTREAM, new to SQL Server 2008. In this post we will look at retrieving a file from SQL Server using FILESTREAM. If you missed yesterday’s installment, a simple front end was created, the full project can be found at the Code Gallery site http://code.msdn.microsoft.com/FileStreamFTS .

The interface is very simple:

The grid is a Data View Grid that shows the ID and Document information from the table we previously created. (If you want to see the code to populate the grid see the project.) The user picks a row, then clicks on the Get File button.

private void btnGetFile_Click(object sender, EventArgs e)

{

// Reset in case it was used previously

lblStatus.Text = "";

if (dgvFiles.CurrentRow != null)

{

// Grab the ID (Primary Key) for the current row

int ID = (int)dgvFiles.CurrentRow.Cells[0].Value;

// Now Save the file to the folder passed in the second

// paramter.

FileTransfer.GetFile2(ID, @"D:\Docs\Output\");

// And let user know it’s OK

lblStatus.Text = "File Retrieved";

}

}

The code is very simple, the heart of it is the FileTransfer.GetFile static method. Two values are passed in, the integer ID, which is the primary key from the database, and the path to save the file to. Here I simply hard coded a path, in a real life application you will want to give the user the ability to enter a path. Let’s take a look at the GetFile routine.

public static void GetFile(int ID, string outputPath)

{

// Setup database connection

SqlConnection sqlConnection = new SqlConnection(

"Integrated Security=true;server=(local)");

SqlCommand sqlCommand = new SqlCommand();

sqlCommand.Connection = sqlConnection;

try

{

sqlConnection.Open();

// Everything we do with FILESTREAM must always be in

// creating one.

SqlTransaction transaction

= sqlConnection.BeginTransaction("mainTranaction");

sqlCommand.Transaction = transaction;

// The SQL gives us 3 values. First the PathName() method of

// the Document field is called, we’ll need it to use the API

// Second we call a special function that will tell us what

// the context is for the current transaction, in this case

// the "mainTransaction" we started above. Finally it gives

// the name of the document, which the app will use when it

// creates the document but is not strictly required as

// part of the FILESTREAM.

sqlCommand.CommandText

= "SELECT Document.PathName()"

+ ", GET_FILESTREAM_TRANSACTION_CONTEXT() "

+ ", DocumentName "

+ "FROM FileStreamFTS.dbo.DocumentRepository "

+ "WHERE ID=@theID ";

"@theID", SqlDbType.Int).Value = ID;

{

throw new Exception("Unable to get BLOB data");

}

// OK we have some data, pull it out of the reader into locals

int length = context.Length;

// Now we need to use the API we declared at the top of this class

// in order to get a handle.

SafeFileHandle handle = OpenSqlFilestream(

path

, SQL_FILESTREAM_OPEN_NO_FLAGS

, context

, (UInt32)length, 0);

// Using the handle we just got, we can open up a stream from

// the database.

FileStream databaseStream = new FileStream(

// This file stream will be used to copy the data to disk

FileStream outputStream

= File.Create(outputPath + outputFilename);

// Setup a buffer to hold the streamed data

int blockSize = 1024 * 512;

byte[] buffer = new byte[blockSize];

// There are two ways we could get the data. The simplest way

// is to read the data, then immediately feed it to the output

// stream using it’s Write feature (shown below, commented out.

// The second way is to load the data into an array of bytes

// (here implemented using the generic LIST). This would let

// you manipulate the data in memory, then write it out (as

// shown here), reupload it to another data stream, or do

// something else entirely.

// If you want to go the simple way, just remove all the

// fileBytes lines and uncomment the outputStream line.

List<byte> fileBytes = new List<byte>();

{

//outputStream.Write(buffer, 0, buffer.Length);

foreach (byte b in buffer)

}

// Write out what is in the LIST to disk

foreach (byte b in fileBytes)

{

byte[] barr = new byte[1];

barr[0] = b;

outputStream.Write(barr, 0, 1);

}

// Close the stream from the databaseStream

databaseStream.Close();

// Write out the file

outputStream.Close();

// Finally we should commit the transaction.

sqlCommand.Transaction.Commit();

}

catch (System.Exception ex)

{

MessageBox.Show(ex.ToString());

}

finally

{

sqlConnection.Close();

}

return;

}

The routine kicks off by opening a connection, then establishing a transaction. Remember from the previous lesson that every time you work with a FILESTREAM it has to be in a transaction. Next we basically duplicate the SQL used in the previous lesson, returning the path name, transaction context, and document name. The only difference is we pass in the ID as a parameter. With that, just like with the previous example we call the OpenSqlFilestream API. Note a difference, in this example the second parameter is “DESIRED_ACCESS_READ” as opposed to the write access we indicated previosly.

Once we have the “handle” we can create a FileStream for reading from the database. In this example I loop through the file stream, loading the data into a LIST of bytes. Once in memory we are free to work with it as we need to. In this example I simply loop back through the generic List and write the data to the file stream we opened on the disk for writing. If all you are doing is writing, it would be somewhat more efficient to write the code like so:

{

outputStream.Write(buffer, 0, buffer.Length);

}

// Close the stream from the databaseStream

databaseStream.Close();

I simply eliminate the local byte array and write the buffer directly to the disk. Either way, the remainder is simple, just closing all the streams, commiting the transaction and closing the database connection.

This concludes the series on how to use FILESTREAM, in future posts we look into how to do Full Text Search with FILESTREAM stored objects.

## Accessing FILESTREAM Data From A Client .NET Application – Part 1 Uploading a File

The best way to work with documents in a database is via a .Net application. I created a simple Windows forms project to access the table I created in previous lessons. I named the application FileLoader, you can the entire project at the Code Gallery site http://code.msdn.microsoft.com/FileStreamFTS .

The interface is very simple:

As you can see there are two main functions, the upper half uploads a file to the SQL Server. The lower half displays the files already in the table, lets the user pick one and then click the GetFile button to save it locally. Today we’ll look at the Upload File functionality. Here is the code:

private void btnUploadFile_Click(object sender, EventArgs e)

{

// Reset in case it was used previously

lblStatus.Text = "";

// Make sure user entered something

if (txtFile.Text.Length == 0)

{

MessageBox.Show("Must supply a file name");

lblStatus.Text = "Must supply file name";

return;

}

// Make sure what user entered is valid

FileInfo fi = new FileInfo(txtFile.Text);

if (!fi.Exists)

{

MessageBox.Show("The file you entered does not exist.");

lblStatus.Text = "The file you entered does not exist.";

return;

}

// Upload the file to the database

// Refresh the datagrid to show the newly added file

// Let user know it was uploaded

lblStatus.Text = fi.Name + " Uploaded";

}

The real line of importance is the FileTransfer.UploadFile. This calls a static method in a class I named FileTransfer.cs. In order to use FILESTREAM there is an API call we have to make, so at the header area of the FileTransfer we have a lot of declarations. These are pretty much a straight copy from the MSDN help files.

//These contants are passed to the OpenSqlFilestream()

//API DesiredAccess parameter. They define the type

//of BLOB access that is needed by the application.

const UInt32 DESIRED_ACCESS_WRITE = 0x00000001;

//These contants are passed to the OpenSqlFilestream()

//API OpenOptions parameter. They allow you to specify

//how the application will access the FILESTREAM BLOB

//data. If you do not want this ability, you can pass in

//the value 0. In this code sample, the value 0 has

//been defined as SQL_FILESTREAM_OPEN_NO_FLAGS.

const UInt32 SQL_FILESTREAM_OPEN_NO_FLAGS = 0x00000000;

const UInt32 SQL_FILESTREAM_OPEN_FLAG_ASYNC = 0x00000001;

const UInt32 SQL_FILESTREAM_OPEN_FLAG_NO_BUFFERING = 0x00000002;

const UInt32 SQL_FILESTREAM_OPEN_FLAG_NO_WRITE_THROUGH = 0x00000004;

const UInt32 SQL_FILESTREAM_OPEN_FLAG_SEQUENTIAL_SCAN = 0x00000008;

const UInt32 SQL_FILESTREAM_OPEN_FLAG_RANDOM_ACCESS = 0x00000010;

//This structure defines the format of the final parameter to the

//OpenSqlFilestream() API.

//This statement imports the OpenSqlFilestream API so that it

//can be called in the Main() method below.

[DllImport("sqlncli10.dll", SetLastError = true, CharSet = CharSet.Unicode)]

static extern SafeFileHandle OpenSqlFilestream(

string Filestreamath,

uint DesiredAccess,

uint OpenOptions,

byte[] FilestreamTransactionContext,

uint FilestreamTransactionContextLength,

Int64 AllocationSize);

//This statement imports the Win32 API GetLastError().

//This is necessary to check whether OpenSqlFilestream

//succeeded in returning a valid / handle

[DllImport("kernel32.dll", SetLastError = true)]

static extern UInt32 GetLastError();

OK, with that out of the way, I’ve created a public, static method to upload the file. Here is the full routine:

{

// Establish db connection

SqlConnection sqlConnection = new SqlConnection(

"Integrated Security=true;server=(local)");

SqlTransaction transaction = null;

// Create a File Info object so you can easily get the

// name and extenstion. As an alternative you could

// choose to pass them in,  or use some other way

// to extract the extension and name.

FileInfo fi = new FileInfo(fileName);

try

{

// Open the file as a stream

FileStream sourceFile = new FileStream(fileName

// Create the row in the database

sqlConnection.Open();

SqlCommand cmd = new SqlCommand();

cmd.Connection = sqlConnection;

cmd.CommandText = "INSERT INTO "

+ "FileStreamFTS.dbo.DocumentRepository"

+ "(DocumentExtension, DocumentName) VALUES (‘"

+ fi.Extension + "’, ‘"

+ fi.Name + "’)";

cmd.ExecuteNonQuery();

// Now upload the file. It must be done inside a transaction.

transaction = sqlConnection.BeginTransaction("mainTranaction");

cmd.Transaction = transaction;

cmd.CommandText = "SELECT Document.PathName(), "

+ "GET_FILESTREAM_TRANSACTION_CONTEXT() "

+ "FROM FileStreamFTS.dbo.DocumentRepository "

+ "WHERE ID=(select max(id) from FileStreamFTS.dbo.DocumentRepository)";

{

throw new Exception("Could not get file stream context");

}

// Get the path

string path = (string)rdr[0];

// Get a file stream context

byte[] context = (byte[])rdr[1];

int length = context.Length;

rdr.Close();

// Now use the API to get a reference (handle) to the filestream

SafeFileHandle handle = OpenSqlFilestream(path

, DESIRED_ACCESS_WRITE

, SQL_FILESTREAM_OPEN_NO_FLAGS

, context, (UInt32)length, 0);

// Now create a true .Net filestream to the database

// using the handle we got in the step above

FileStream dbStream = new FileStream(handle, FileAccess.Write);

// Setup a buffer to hold the data we read from disk

int blocksize = 1024 * 512;

byte[] buffer = new byte[blocksize];

// Read from file and write to DB

{

dbStream.Write(buffer, 0, buffer.Length);

}

// Done reading, close all of our streams and commit the file

dbStream.Close();

sourceFile.Close();

transaction.Commit();

}

catch (Exception e)

{

if (transaction != null)

{

transaction.Rollback();

}

throw e;

}

finally

{

sqlConnection.Close();

}

}

First we open a connection to the SQL Server, then create a FileInfo object to make it simple to extract the file name and extension. Next a record is inserted into the database that will act as a place holder. It has the name of the file and the extension, but no file yet. I did go ahead and open a FileStream to the source file, located on the disk. We’ll need this later to upload the file.

Next you will see that I begin a transaction. Every time you work with a FILESTREAM it must always be in the context of a transaction. After that a SQL Data Reader is created that has three pieces of information. First, it calls the PathName() function for the Document field in our table. The PathName() will be needed later when we call the API. The second field is returned from the GET_FILESTREAM_TRANSACTION_CONTEXT function, and returns the transaction context for the transaction. Note this is not the name (in this example “mainTransaction”), but the context which is a special value. These two values are then copied into local variables which will be used in calling the OpenSqlFilestream API. In this example I also retrieve the DocumentName field, this is used by the code when it writes the file to the database, but is not strictly needed for the FILESTREAM.

Next you will see the call to the OpenSqlFilestream API, which returns a “handle”. This handle is then used to create a FileStream object. Using this newly created FileStream (here named dbStream) we can then upload the file. Now the main work begins. After setting up a buffer, we then simply read from the source file stream into the buffer, then write the exact same buffer to the database FileStream. The loop continues until there are no more bytes in the source.

At this point we are essentially done. We close the streams, commit the transaction, and in the finally block close the SQL database connection. The file should now be in the database. I do want to point out one thing. In the SQL to get the information to the row just uploaded, I use a subquery to get the max(id), essentially returning the last row just inserted. This is fine for this simple example, when the database has just one user. In your production systems where you are likely to have many users, however, you should use an alternate method to return the row you need. Otherwise two users could insert rows at the same time, and thus a conflict could occur with both of them getting back the same max(id). It will not happen often, but at some point it could happen and be very hard to debug.

This handled the uploading of files to the SQL Server via FILESTREAM, in the next installment we’ll look at how to retrieve the file we just uploaded.

## Generating a PDF file from a Reporting Services Report Viewer Control

In yesterday’s post, I demonstrated how to generate a SQL Server Reporting Services report without having to have SQL Server Reporting Services. The sample application used the Microsoft Report Viewer control to display the report. A common need in business is to generate documents, such as PDFs, that will later be archived. It turns out if you are using a report viewer control, this is easy to do programmatically.

First, you need to add one using statement to the top of your class, in addition to the others that were added yesterday.

using System.IO;

Next, we only need a few lines of code to generate the PDF.

Warning[] warnings;

string[] streamids;

string mimeType;

string encoding;

string extension;

byte[] bytes = reportViewer1.LocalReport.Render(

"PDF", null, out mimeType, out encoding, out extension,

out streamids, out warnings);

FileStream fs = new FileStream(@"D:\ReportOutput.pdf", FileMode.Create);

fs.Write(bytes, 0, bytes.Length);

fs.Close();

This code snippet came right from the MSDN Books on Line, and is pretty simple. I could have selected another format by changing the first value passed into the Render method, for example “EXCEL” would have rendered it as a Microsoft Excel document.

In the code samples I placed the above sample in it’s own button, but I could just have easily placed it under one of the other demo buttons.

This ability brings up some interesting possibilities. For example, the report viewer control does not have to be visible to the user in order for this to work. Thus you could create an application that every night generated a series of reports and saved them as PDFs to some central location, such as a web server or document control server. All the user (assuming one was around) would have to see is a progress bar, the reports themselves never get displayed.

## Using SQL Server Reporting Services in Client Mode

Recently I did a presentation at the March BSDA meeting. I showed how to use SQL Server Reporting Services without a SQL Server, or more specifically a SQL Server running Reporting Services. It got an enthusiastic response so I thought I’d add to it here by adding some reminder documentation, as much for myself as for all of you wonderful readers.

Using Reporting Services in Client, or Local mode is a 4 step process. First, you will need an XSD schema file to create the report on. Once you have the XSD you will be able to move to the second step, creating the report. Third you will need to place a Report Viewer control on your windows form, WPF form, or ASP.NET page. Finally you will need to write some code that generates an ADO.NET dataset, loads the report in the report viewer control, then binds it all together. Lets look at this step by step.

Normally when you create a report you connect to a database, then base it off of some object like a query, view, or stored procedure. The report is then uploaded to a Reporting Services server, which takes care of hosting it, displaying it, and generating the data for it. With client mode you have no server available, so we have to instead create a surrogate. That’s where our XSD file comes in.

Right click in Solution Explorer and “Add a new item”, and from the list of goodies select “XML Schema”. Name it something appropriate, letting the default extension be XSD. For this example I will be getting customer order data, so I’ve given it the name CustomerOrders.xsd. Visual Studio will think about it then add it to the project, and even helpfully open it for you. I don’t know about you, but hand typing XML Schema’s isn’t my idea of fun, so you should glace at it, go “that’s nice” then close it.

Now right click on the XSD file in Solution Explorer, and pick “Open with….”. In the dialog that appears, select “Dataset Editor”. When you do, Visual Studio presents a big scary warning message letting you know that you could lose contents, and that this will forever be a dataset XSD file. We have nothing in the file, so we’re cool with this, just click OK.

You will now be presented with a big surface area. In the middle it tells you to drag items from the server explorer or right click. If you have a table, view, or stored procedure you are free to drag it in, but most of the time you’ll want to base this off of a SQL query. Right click on the surface, and select Add…., Table Adapter from the menu. The first screen asks you for the database connection. This is the only time you’ll actually need a connection, in this example I am using the good old Northwind database. I pointed at Northwind and clicked next.

Next we are asked how we are going to access the data. Since we have a SQL Statement just pick the default of “Use SQL statements” and click Next.

Now take your SQL Statement and paste it in, and click Next.

OK, click Finish to wrap up the addition of the XSD. By default the adapter has a generic name, we should give ours something more meaningful. Click in the top bar, then enter a new name. Since my example report is for customer order data, I’ll name it CustomerOrders. I then went to the bottom bar and renamed the TableAdapter1 to CustomerOrderTableAdapter. You should now see something like:

Note that this will become your Data Source for the report. The data source will have the name of the XSD followed by the name of the source, in this case it will read CustomerOrders_CutomerOrders. OK, now it’s time to create the report.

Go back to Solution Explorer, right click and pick Add New Item. Navigate to the Reporting area and pick Report Wizard. Note the file extension should end in RDLC. If you have used Reporting Services before, you will know that reports typically end in RDL. However, client mode reports have just a slightly different syntax to them, thus the RDLC extension to differentiate the two. While you can modify an RDL to become an RDLC and vice versa, you have to do so by hacking the XML behind the report.

Note you can also choose just Report, but then you’ll have to setup everything manually. For this simple example though, we’ll just use the Report Wizard.

Give your report a meaningful name and click Add. The report wizard then shows you a welcoming screen if you’ve never run it before, just click Next.

Now we need to pick the data source. In this example, you want the CustomerOrders branch, so select it and click Next.

The next screen asks if we want a Tabular or Matrix report. Select the one for you, in my example I picked Tabular and clicked Next. The next screen asks how we want to display the data. For my example, I opted to group by the customers company name and contact name, then the order data went into the details area. Fill out as appropriate for your report and click Next.

The next screen asks how we want things laid out. This affects the look and feel of the report. For my example I just took the default and clicked next, however you are free to play with this to experiment with the different looks and feels your reports might have.

Likewise the next screen is also a look and feel one, asking what colorings we want to apply. Pick one that makes you happy and click next. You can always change it later, many times I pick the Generic one (which adds no colors) then fix it up afterward.

The final screen is the wrap up. Give your report a meaningful name and click Finish.

OK, you have a report, now you need a container. Open up the user interface you want to place the report viewer control on. In my example I went with a very simple Windows Forms application.

In my toolbox, I navigated to the Reporting section, where I only found one control, the MicrosoftReportViewer control. (Note I am using Visual Studio 2008 SP1, if you are on an earlier version your names may differ slightly). Grab it and drop it onto your design surface. I also added a Button control to the form to kick off the report display process.

Now it’s time for the last step, adding some code. In this example I’ve used a Windows Form. Opening it, the first thing we find in the form load area is::

this.reportViewer1.RefreshReport();

(Note I left my report viewer control named reportViewer1.) Delete it, we’ll have it refresh elsewhere.

Now we need to add some using statements to the top of our class.

//Add these to the standard list above

using System.Data.Sql;

using System.Data.SqlClient;

using Microsoft.Reporting.WinForms;

The first two will be used in accessing our Northwind database, you may need to use different libraries if you were going to another database. I’ve also included a referenced to the Reporting.WinForms library so we can manipulate the report programmatically.

Now let’s go to the code for the button click event. First, we need to reset the report viewer in case we’d been using it to host another report.

// Reset in case report viewer was holding another reportViewer1

reportViewer1.Reset();

Next We need to set the report viewer to local mode. This tells it we’ll be supplying the report name from a local file, and binding the report to a local ADO.NET datasource.

// Set the processing mode for the ReportViewer to Local

reportViewer1.ProcessingMode = ProcessingMode.Local;

Our third step is to create a local report variable, and set it’s reference to the report viewer’s local report. This will make it easier to work with. Then we’ll set the location of the report we want to use.

LocalReport localReport = reportViewer1.LocalReport;

localReport.ReportPath = @"D:\Presentations\SQL Server\SSRS RDLC\SSRS_RDLC\Report2.rdlc";

Now we need to create an ADO.Net dataset, and populate it. I implemented most of that functionality in a method called GetCustomerOrders, which I’ll append at the bottom of these instructions. It’s very straight forward code.

DataSet dataset = new DataSet("Northwind");

// Get the sales order data

GetCustomerOrders(ref dataset);

At this stage we have told it where our report is, and have created the dataset. Now we need to create a datasource for the report itself. We’ll use the ReportDataSource object. For the name, we’ll use the same name as the XSD schema, CustomerOrders_CustomerOrders. Then for the value we will give it the table from the dataset we created in code. It’s possible for a report to have multiple datasets, in the report we’d give each one it’s own name (based on the XSD) then here we’d bind the dataset table to the name we’d used in the report. Once done we will then add the new ReportDataSource to the local reports DataSources collection. Finally, we’ll referesh the report viewer to make it generate the report.

// Create a report data source for the sales order data

ReportDataSource dsCustomers = new ReportDataSource();

dsCustomers.Name = "Customers_Customers";

dsCustomers.Value = dataset.Tables["Customers"];

// Refresh the report

reportViewer1.RefreshReport();

You can download a copy of these instructions, along with the entire sample project including code and reports, at the Microsoft Code Gallery site http://code.msdn.microsoft.com/SqlServerRSClient . As promised, below is a copy of the GetCustomerOrders routine, for your reference.

private void GetCustomerOrders(ref DataSet dsNorthwind)

{

string sqlCustomerOrders = "SELECT c.[CustomerID]"

+ " ,c.[CompanyName]"

+ " ,c.[ContactName]"

+ " ,c.[ContactTitle]"

+ " ,c.[City]"

+ " ,c.[Region]"

+ " ,c.[PostalCode]"

+ " ,c.[Country]"

+ " ,c.[Phone]"

+ " ,c.[Fax]"

+ " ,o.[OrderID]"

+ " ,o.[CustomerID]"

+ " ,o.[EmployeeID]"

+ " ,o.[OrderDate]"

+ " ,o.[RequiredDate]"

+ " ,o.[ShippedDate]"

+ " ,o.[ShipVia]"

+ " ,o.[Freight]"

+ " ,o.[ShipName]"

+ " ,o.[ShipCity]"

+ " ,o.[ShipRegion]"

+ " ,o.[ShipPostalCode]"

+ " ,o.[ShipCountry]"

+ "  FROM [Northwind].[dbo].[Customers] c"

+ "  join [Northwind].[dbo].[Orders] o on c.CustomerID = o.CustomerID";

SqlConnection connection = new

SqlConnection("Data Source=(local); " +

"Initial Catalog=Northwind; " +

"Integrated Security=SSPI");

SqlCommand command =

new SqlCommand(sqlCustomerOrders, connection);

}

## Presenting Getting Started with SQL Server Compact Edition 3.5 at BUG.NET Meeting

Just wanted to let everyone know I’ll be doing a presentation this coming Tuesday night, August the 12th for the Birmingham .Net Users Group (BUG.NET). My topic, as you may have guessed from the title, will be using SQL Server Compact Edition.

While I will be using Visual Studio 2008, I will point out which pieces are 2005 compatible. I will also cover the use of both traditional coding techniques as well as how to use LinqToSQL to talk to the Compact Edition.

The meeting takes place at 6:30 pm at New Horizons Training Center in Homewood.

I also plan a new series of blog posts to start later this week on the subject, and will be creating a new Code Gallery site to hold my examples.

Also, don’t forget the regular BSDA meeting this coming Thursday night, the 14th. Also starting at 6:30 pm at New Horizons, Shannon Brooks-Hamilton, a software usability expert, will be there to talk about user interface design. Lots of good thought material on how we can make better UIs for our users.