tailieunhanh - Microsoft SQL Server 2005 Developer’s Guide- P46

Microsoft SQL Server 2005 Developer’s Guide- P46:SQL Server 2005 is a feature-rich release that provides a host of new tools and technologies for the database developer. This book is written to help database developers and DBAs become productive immediately with the new features and capabilities found in SQL Server 2005. | Chapter 11 Developing BI Applications with 429 End If Next iField Add the item to the listview lvItem Loop While Close the DataReader Catch ex As Exception End Try End Sub Private Function ParseColName ByRef sColName As String As String Dim sShortName As String Dim iFound As Integer 1 sShortName iFound - _ iFound 1 Return sShortName End Function At the top of the subroutine you can see that an AdomdConnection object is passed in. The next statement creates a new AdomdCommand object named cmd and uses an MDX SELECT statement as a parameter on the constructor. This very simple MDX SELECT statement when executed will set the column and row dimensions of the multidimensional results with employee last names and English name months. The NON EMPTY keywords are used so that only the nonempty data will be selected. Next an AdomdDataReader is initialized to receive the multidimensional data and a ListViewItem object is initialized. The next two lines clear the Items and Columns from the ListView control that was placed on the Windows form at the program design phase. The AdomdCommand s ExecuteReader method is then called and returns the AdomdDataReader named dr. As you can see from the code listing the ExecuteReader is called inside the Try-Catch loop. Any exceptions that may occur are trapped by the Try-Catch loop and a message will be displayed to the user. After the data has been retrieved with the ExecuteReader method and output to the dr AdomdDataReader object the Read method of the dr object is called to read the first data and set up the column names for output to the ListView control. The next few lines of code use a For Next loop to add columns to the ListView control. In this example the dr object s GetName method is used to set the column text with the names of the 430 Microsoft SQL Server 2005 .

TỪ KHÓA LIÊN QUAN