You are on page 1of 9

Data Grid Tutorial for sw9mba

After you have placed the grid on your form, right click on the Forms ~~> Data Environment as shown below and add a
DataEnvironment in your application.
To add a database inside your DataEnvironmen, just right click in Connection1 and select Properties.
Click on properties as sown above and adjust your data engine to work with your database by selecting the correct provider.
After that, go to connection tab to select or enter the database file name and path, and to test the connection.
After testing the connection, this message box will appear.
To insert the tables inside the DataEnvironment, right click the connection1 and select Add Command.
Right click the Command1, and select Properties.
This window will appear.
In Database Object select Table and from Object Name select the table that you want to connect the Connection1 with.
Then click OK.
The connection will appear like that.
.
Set the properties of the command1 as below
Write this code in the code side for the DataEnvironment:
Private Sub DataEnvironment_Initialize()
'~~> Replace the Data Source with the correct path name and file
DataEnvironment1.Connection1.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& App.Path & "\koolsid.mdb;Persist Security Info=False"
End Sub
Like this picture.
Right click on the DataGrid control on the form1 and select Edit. Nothing will pop up . Now right click again over the control and
select Append to add a column as in the table in the database. Like this picture.
To connect the DataGrid control with the DataEnvironment, just go to the Data Source property for the DataGrid Control and
change it to be DataEnvironment1 like the picture.
And the Data Member to be your table name which is placed in the DataEnvironment. Like the picture.
Right click again over the DataGrid Control and select Properties.
You will be presented with.
Just change the options like the followed picture.
Move to the Columns Tab.
Select your 1
st
column and set a caption for it. After that you can set the Data field it corresponds to Repeat these steps for all
columns
Your application should be finally like this:
There you go you are ready, simply run it:

You might also like