The example is now complete, you may want to save your display, and then go into Runtime mode to try it out. We preferred to do it this way for readability and ease of understanding. NOTE: The function body can easily be collapsed to a single line if you specify the query in the PopulateGrid call, instead of defining a variable for it. Last line calls the function we defined earlier to populate the data grid. The first two lines define the query to select all the records from the SalesLT.Product table. PopulateGrid( "DataGridView1", commandString) To do so we fill the button’s click as follows:ĬommandString = "SELECT * FROM SalesLT.Product" The last thing we need to do to complete our example is to call our PopulateGrid function when the button is clicked. This is all we need to access the database and populate the data grid. In the last block, we get a reference to the data grid, and then we fill its DataSource property with the DataTable object created earlier. We also create and prepare a SqlDataAdapter and a DataTable object. Using this connection, we prepare a SqlCommand object, passing it the query we got as a parameter. We start creating a SqlConnection using the connection string we built before. In the first block, we have declared all the variables we are going to use here. In the function, you can identify three different blocks. Get the control and give it properties This function is made to accept two parameters: the name of the grid to populate, and the query to use to get the data.įunction PopulateGrid(gridName, commandString) Next, we write the utility function that will populate the grid. You can see that we have used “(local)” as our data source, because the server is local, and the database name is “AdventureWorksLT”. Our connection string is defined in the script module as shown below:Ĭatalog=AdventureWorksLT Integrated Security=SSPI" In this example, we show the easiest possible configuration, with the server running locally and using the integrated security.
Yours might be slightly different, depending on the location of your SQL Server, the database name, and eventually the security settings. Let us start by defining the connection string.
The script code we are going to write consists of the following: We just need to write some script to have it connect to our database. Your current display should look similar to Figure 2, where the selected gray rectangle is the DataGridView control in configuration mode.įigure 2 - Display with a DataGridView Control and Button Drag this control on the screen, and size it as desired. Browse for the usually located in C:\Windows\Microsoft.NET\Framework64\v7.
NOTE: If you do not see the “DataGridView”, you can add it by clicking the “Add/Remove Components” button on the Windows Forms Toolbox. You can access this user control from the Toolbox, selecting the category “Windows Forms” as shown in Figure 1.įigure 1 - The DataGridView Control in the Toolbox
To show the database content we will use the.
NOTE: If you need more information on how to create simple scripts in GraphWorX64, refer to the Scripting - Quick Start and Scripting Basics topics. Set the pick action for the button to be “Run Script”, and double-click the “RunScript” event to generate the script function associated to this button. The first step, we will create a new GraphWorX64 display, where we will insert a button. Once you have chosen the database you intend to use for this example, you are ready to start. We have used the lite version of this database, which is called AdventureWorksLT.
If you want to use the same sample database we will use in this Application Note, then you can freely download it from CodePlex at under the SQL Server 2005 examples. The only difference in this example will be in the connection string and the query used to access the database.
This is the SQL Server 2005 equivalent of the well-known NorthWind database, which was created for previous versions of SQL Server.įeel free to use your already existing database, or to create a new one if you prefer. In this topic, we demonstrate how to access your data from a database.įor this example, we are going to use a default sample database, which has been created for SQL Server 2005, called AdventureWorks. You can further use this data in generating your display content automatically, populating a 3D View control’s content, or animating some elements on the screen, just to name few. You can visualize the information in your database in GraphWorX64. It might be useful to be able to interface with such database to extract the data that you need to use inside your GENESIS64 application.
More and more often, an organization’s information is stored inside a database.