GrapeCity MultiRow Windows Forms Documentation
Connecting to SQL Server Database

MultiRow can connect to a SQL Server database using ADO.NET in the same way as the standard .NET Framework controls.

Assumptions

This topic assumes that the following are being used:

Reference: Installing Sample Database

The sample database is not installed by default with Microsoft SQL Server. After installing Microsoft SQL Server, refer to the Microsoft SQL Server documentation and MSDN to install the sample database. An example of the installation steps is provided below.

  1. Install Microsoft SQL Server. The steps below are for the Express Edition but most of them can be used irrespective of the Visual Studio version.
  2. Website Download Northwind and pubs Sample Databases for SQL Server 2000 http://www.microsoft.com/downloads/details.aspx?FamilyId=06616212-0356-46A0-8DA2-EEBC53A68034. This database is for Microsoft SQL Server 2000, but can also be used with Microsoft SQL Server 2005 or 2008.
  3. Install the downloaded samples. The default installation folder is C:\SQL Server 2000 Sample Databases.
  4. Install Microsoft SQL Server Management Studio Express.
  5. Run Microsoft SQL Server Management Studio Express as Administrator and connect to Microsoft SQL Server. Example of server name: (local)\SQLEXPRESS
  6. Select Databases from the tree on the left and click on the Attach menu of the context menu.
  7. Click the Add button on the Attach Databases page.
  8. On the Locate Database Files page, select C:\SQL Server 2000 Sample Databases\NORTHWND.MDF and click OK.
  9. Click OK on the Attach Databases page.
  10. Expand databases in the tree on the left and check if Northwind has been added.

Connecting to Database

Register the SQL Server datasource into the project. This operation is not dependent on MultiRow.

  1. Start Visual Studio and create a new Windows application.
  2. Click Data - Add New Data Source in Visual Studio.
  3. On the Data Source Configuration Wizard page, select Database and click Next.
  4. On the Choose Your Data Connection page, click on New Connection and add a connection with the following configuration.
    • Data source - Microsoft SQL Server (SqlClient)
    • Server name (Example) - (local)\SQLEXPRESS
    • Select or enter a database name - Northwind
  5. After adding the connection, click Next.
  6. On the Save the Connection String to the Application Configuration File page, click Next.
  7. On the Choose your Database Objects page, check the following table:
    • Orders

    Data Source Configuration Wizard

    A section of Data Source Configuration Wizard

  8. Click Finish.
  9. Check that Orders has been added to the Data Sources window of Visual Studio.

    A section of Data Source Configuration Wizard

Designing Templates

Create a template for MultiRow based on the database definition.

  1. Click Project - Add New Item in Visual Studio.
  2. On the Add New Item page, select the MultiRow 7.0 Templates and click on the Add button.

    Add New Item

  3. Check that the Template1.vb or Template1.cs design page is displayed.

    Template Designer

  4. Click Data - Show Data Sources in Visual Studio.

    Template Designer

  5. Select the Orders table under the NorthwindDataSet from the tree in the Data Sources window. Drag and drop it to the Row area while pressing the Ctrl key.

    Template Designer

  6. Double-click on the edges of the row and adjust the height of the row.
  7. Click on Template - CellDisplayMode - DataField in Visual Studio and verify that the data fields have been assigned to the cells.

    Template Designer

  8. Save the project and use the next set of steps provided in Binding the Grid to Data.

Binding the Grid to Data

Place the GcMultiRow control on the form and assign the data source and template to the grid.

  1. Open the design view of the form (Form1).
  2. Select the Orders table from the Data Sources window and click Customize... from the drop-down list.
  3. On the Options page that is displayed, check GcMultiRow in the list of Associated controls.

    Template Designer

  4. Close the dialog by clicking on the OK button.
  5. Select the Orders table, and click on GcMultiRow in the drop-down list of the Data Sources window.

    Click on GcMultiRow in the dropdown list.

  6. Drag and drop the Orders table onto the design view of the form (Form1).
  7. Verify that the BindingNavigator (OrdersBindingNavigator) and GcMultiRow (OrdersGcMultiRow) have been placed on the form.

    ordersBindingNavigator and ordersGcMultiRow

  8. Click on Build - Build Solution in Visual Studio.
  9. Select the OrdersGcMultiRow control on the form and select Template1 from the Choose Template option in Smart Tag.

    Smart tag of GcMultiRow control

A template and data source have been assigned to the grid using the above steps. When you run the project, you can see that the values from the datasource have been read into the grid.

Result on running the project

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options