1 / 12

Virtual Table and DataGridView

Virtual Table and DataGridView. Virtual Table DataGridView. Virtual Tables. SQL statements create a new “virtual” table from existing tables. Think of the following statement as creating a "virtual table" SELECT city, pop2015 FROM Cities WHERE pop2015>=20 Results in:.

irving
Download Presentation

Virtual Table and DataGridView

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Virtual Table and DataGridView • Virtual Table • DataGridView Ch. 10

  2. Virtual Tables • SQL statements create a new “virtual” table from existing tables. • Think of the following statement as creating a "virtual table" SELECT city, pop2015 FROM Cities WHERE pop2015>=20 • Results in: city pop2015Bombay 22.6Delhi 20.9 Mexico City 20.6 Sao Paulo 20.0Tokyo 36.2 Ch. 10

  3. Another Virtual Table SELECT * FROM Countries WHERE country Like 'I%' ORDER BY pop2005 ASC • Results in: country pop2005 monetaryUnit Indonesia 222.8 rupiahIndia 1103.4 rupee Ch. 10

  4. Views • “Virtual” tables don’t exist physically. • For all practical purposes, Visual Basic acts as if they did. • You may also see a “virtual” table called a view. Ch. 10

  5. The DataGridView Control • The DataGridView displays the values for an entire view in a table format similar to the table displayed by Database Explorer. • The prefix for the name of a DataGridView control is dgv. • After a data table has been filled, the statement dgvDisplay.DataSource = dt displays the contents of the data table dt in the data grid. Ch. 10

  6. Lab sheet 10.5: Form dgvDisplay Ch. 10

  7. Lab sheet 10.5: Code Private SubfrmCities_Load(...) Handles MyBase.Load UpdateGrid("Select * From Cities") End Sub Private SubbtnOrderbyPop_Click(...) HandlesbtnOrderbyPop.Click UpdateGrid("Select * From Cities Order By pop2005 ASC") End Sub Private SubbtnShowMonUnit_Click(...) _ HandlesbtnShowMonUnit.Click UpdateGrid("SELECT city, Cities.country, " & _ "Cities.pop1995, monetaryUnit " & _ "FROM Cities INNER JOIN Countries " & _ "ON Cities.country=Countries.country " & _ "ORDER BY city ASC") End Sub Ch. 10

  8. Example Lab sheet 10.5: Code continued SubUpdateGrid(ByValsqlStr As String) Dimdt As NewDataTable() DimconnStr As String="Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source = MEGACITIES.MDB" DimdataAdapter As NewOleDb.OleDbDataAdapter(sqlStr, connStr) dataAdapter.Fill(dt) dataAdapter.Dispose() dgvDisplay.DataSource = dt End Sub Ch. 10

  9. Lab sheet 10.5: Output Click on the “Show Monetary Unit” button. Ch. 10

  10. Lab sheet 10.6: Form txtCountry dgvDisplay Ch. 10

  11. Lab sheet 10.6: Code Private SubbtnFindCities_Click(...) _ HandlesbtnFindCities.Click UpdateGrid("SELECT city FROM Cities WHERE" & _ "country = '" & txtCountry.Text & _ "' ORDER BY city ASC") End Sub SubUpdateGrid(ByValsqlStr As String) (Boilerplate, except for Dim sqlStr statement) Ifdt.Rows.Count = 0 Then MsgBox("No cities from that country " & _ "in the database") Else dgvDisplay.DataSource = dt End If End Sub Ch. 10

  12. Lab sheet 10.6: Output Ch. 10

More Related