- GUI
- Windows API tutorial
- Introduction to Windows API
- Windows API main functions
- System functions in Windows API
- Strings in Windows API
- Date & time in Windows API
- A window in Windows API
- First steps in UI
- Windows API menus
- Windows API dialogs
- Windows API controls I
- Windows API controls II
- Windows API controls III
- Advanced controls in Windows API
- Custom controls in Windows API
- The GDI in Windows API
- PyQt4 tutorial
- PyQt5 tutorial
- Qt4 tutorial
- Introduction to Qt4 toolkit
- Qt4 utility classes
- Strings in Qt4
- Date and time in Qt4
- Working with files and directories in Qt4
- First programs in Qt4
- Menus and toolbars in Qt4
- Layout management in Qt4
- Events and signals in Qt4
- Qt4 Widgets
- Qt4 Widgets II
- Painting in Qt4
- Custom widget in Qt4
- The Breakout game in Qt4
- Qt5 tutorial
- Introduction to Qt5 toolkit
- Strings in Qt5
- Date and time in Qt5
- Containers in Qt5
- Working with files and directories in Qt5
- First programs in Qt5
- Menus and toolbars in Qt5
- Layout management in Qt5
- Events and signals in Qt5
- Qt5 Widgets
- Qt5 Widgets II
- Painting in Qt5
- Custom widget in Qt5
- Snake in Qt5
- The Breakout game in Qt5
- PySide tutorial
- Tkinter tutorial
- Tcl/Tk tutorial
- Qt Quick tutorial
- Java Swing tutorial
- JavaFX tutorial
- Java SWT tutorial
- wxWidgets tutorial
- Introduction to wxWidgets
- wxWidgets helper classes
- First programs in wxWidgets
- Menus and toolbars in wxWidgets
- Layout management in wxWidgets
- Events in wxWidgets
- Dialogs in wxWidgets
- wxWidgets widgets
- wxWidgets widgets II
- Drag and Drop in wxWidgets
- Device Contexts in wxWidgets
- Custom widgets in wxWidgets
- The Tetris game in wxWidgets
- wxPython tutorial
- Introduction to wxPython
- First Steps
- Menus and toolbars
- Layout management in wxPython
- Events in wxPython
- wxPython dialogs
- Widgets
- Advanced widgets in wxPython
- Drag and drop in wxPython
- Internationalisation
- Application skeletons in wxPython
- The GDI
- Mapping modes
- Creating custom widgets
- Tips and Tricks
- wxPython Gripts
- The Tetris game in wxPython
- C# Winforms Mono tutorial
- Java Gnome tutorial
- Introduction to Java Gnome
- First steps in Java Gnome
- Layout management in Java Gnome
- Layout management II in Java Gnome
- Menus in Java Gnome
- Toolbars in Java Gnome
- Events in Java Gnome
- Widgets in Java Gnome
- Widgets II in Java Gnome
- Advanced widgets in Java Gnome
- Dialogs in Java Gnome
- Pango in Java Gnome
- Drawing with Cairo in Java Gnome
- Drawing with Cairo II
- Nibbles in Java Gnome
- QtJambi tutorial
- GTK+ tutorial
- Ruby GTK tutorial
- GTK# tutorial
- Visual Basic GTK# tutorial
- PyGTK tutorial
- Introduction to PyGTK
- First steps in PyGTK
- Layout management in PyGTK
- Menus in PyGTK
- Toolbars in PyGTK
- Signals & events in PyGTK
- Widgets in PyGTK
- Widgets II in PyGTK
- Advanced widgets in PyGTK
- Dialogs in PyGTK
- Pango
- Pango II
- Drawing with Cairo in PyGTK
- Drawing with Cairo II
- Snake game in PyGTK
- Custom widget in PyGTK
- PHP GTK tutorial
- C# Qyoto tutorial
- Ruby Qt tutorial
- Visual Basic Qyoto tutorial
- Mono IronPython Winforms tutorial
- Introduction
- First steps in IronPython Mono Winforms
- Layout management
- Menus and toolbars
- Basic Controls in Mono Winforms
- Basic Controls II in Mono Winforms
- Advanced Controls in Mono Winforms
- Dialogs
- Drag & drop in Mono Winforms
- Painting
- Painting II in IronPython Mono Winforms
- Snake in IronPython Mono Winforms
- The Tetris game in IronPython Mono Winforms
- FreeBASIC GTK tutorial
- Jython Swing tutorial
- JRuby Swing tutorial
- Visual Basic Winforms tutorial
- JavaScript GTK tutorial
- Ruby HTTPClient tutorial
- Ruby Faraday tutorial
- Ruby Net::HTTP tutorial
- Java 2D games tutorial
- Java 2D tutorial
- Cairo graphics tutorial
- PyCairo tutorial
- HTML5 canvas tutorial
- Python tutorial
- Python language
- Interactive Python
- Python lexical structure
- Python data types
- Strings in Python
- Python lists
- Python dictionaries
- Python operators
- Keywords in Python
- Functions in Python
- Files in Python
- Object-oriented programming in Python
- Modules
- Packages in Python
- Exceptions in Python
- Iterators and Generators
- Introspection in Python
- Ruby tutorial
- PHP tutorial
- Visual Basic tutorial
- Visual Basic
- Visual Basic lexical structure
- Basics
- Visual Basic data types
- Strings in Visual Basic
- Operators
- Flow control
- Visual Basic arrays
- Procedures & functions in Visual Basic
- Organizing code in Visual Basic
- Object-oriented programming
- Object-oriented programming II in Visual Basic
- Collections in Visual Basic
- Input & output
- Tcl tutorial
- C# tutorial
- Java tutorial
- AWK tutorial
- Jetty tutorial
- Tomcat Derby tutorial
- Jtwig tutorial
- Android tutorial
- Introduction to Android development
- First Android application
- Android Button widgets
- Android Intents
- Layout management in Android
- Android Spinner widget
- SeekBar widget
- Android ProgressBar widget
- Android ListView widget
- Android Pickers
- Android menus
- Dialogs
- Drawing in Android
- Java EE 5 tutorials
- Introduction
- Installing Java
- Installing NetBeans 6
- Java Application Servers
- Resin CGIServlet
- JavaServer Pages, (JSPs)
- Implicit objects in JSPs
- Shopping cart
- JSP & MySQL Database
- Java Servlets
- Sending email in a Servlet
- Creating a captcha in a Servlet
- DataSource & DriverManager
- Java Beans
- Custom JSP tags
- Object relational mapping with iBATIS
- Jsoup tutorial
- MySQL tutorial
- MySQL quick tutorial
- MySQL storage engines
- MySQL data types
- Creating, altering and dropping tables in MySQL
- MySQL expressions
- Inserting, updating, and deleting data in MySQL
- The SELECT statement in MySQL
- MySQL subqueries
- MySQL constraints
- Exporting and importing data in MySQL
- Joining tables in MySQL
- MySQL functions
- Views in MySQL
- Transactions in MySQL
- MySQL stored routines
- MySQL Python tutorial
- MySQL Perl tutorial
- MySQL C API programming tutorial
- MySQL Visual Basic tutorial
- MySQL PHP tutorial
- MySQL Java tutorial
- MySQL Ruby tutorial
- MySQL C# tutorial
- SQLite tutorial
- SQLite C tutorial
- SQLite PHP tutorial
- SQLite Python tutorial
- SQLite Perl tutorial
- SQLite Ruby tutorial
- SQLite C# tutorial
- SQLite Visual Basic tutorial
- PostgreSQL C tutorial
- PostgreSQL Python tutorial
- PostgreSQL Ruby tutorial
- PostgreSQL PHP tutorial
- PostgreSQL Java tutorial
- Apache Derby tutorial
- SQLAlchemy tutorial
- MongoDB PHP tutorial
- MongoDB Java tutorial
- MongoDB JavaScript tutorial
- MongoDB Ruby tutorial
- Spring JdbcTemplate tutorial
- JDBI tutorial
ADO.NET's DataSet
The ADO.NET architecture consists of two central parts. The .NET Data Providers and the DataSet
. The data providers are components that have been explicitly designed for data manipulation and fast access to data. The DataSet is created for data access independent of any data source. It can be used with multiple and differing data sources, with XML data, or used to manage data local to the application.
A DataSet
is a copy of the data and the relations among the data from the database tables. It is created in memory and used when extensive processing on data is needed or when we bind data tables to a Winforms control. When the processing is done, the changes are written to the data source. The DataSet
is a disconnected relational structure. This means that the underlying connection does not have to be open during the entire life of a DataSet object. This enables us to use efficiently our available database connections.
A DataSet
can be populated in a variety of ways. We can use the Fill()
method of the SqliteDataAdapter
class. We can create programmatically the DataTable
, DataColumn
, and DataRow
objects. Data can be read from an XML document or from a stream.
A SqliteDataAdapter
is an intermediary between the DataSet
and the data source. It populates a DataSet
and resolves updates with the data source. A DataTable
is a representation of a database table in a memory. One or more data tables may be added to a data set. The changes made to the DataSet
are saved to data source by the SqliteCommandBuilder
class.
The DataGridView
control provides a customisable table for displaying data. It allows customisation of cells, rows, columns, and borders through the use of properties. We can use this control to display data with or without an underlying data source.
Creating a DataTable
In the first example, we will work with the DataTable
class.
sqlite> CREATE TABLE Friends2(Id INTEGER PRIMARY KEY, Name TEXT);
In this case, the table must be created before we can save any data into it.
Option Strict On Imports Mono.Data.Sqlite Imports System.Data Module Example Sub Main() Dim cs As String = "URI=file:test.db" Using con As New SqliteConnection(cs) con.Open() Dim table As New DataTable("Friends2") Dim column As New DataColumn Dim row As DataRow column = New DataColumn() column.DataType = System.Type.GetType("System.Int32") column.ColumnName = "Id" table.Columns.Add(column) column = new DataColumn() column.DataType = Type.GetType("System.String") column.ColumnName = "Name" table.Columns.Add(column) row = table.NewRow() row("Id") = 1 row("Name") = "Jane" table.Rows.Add(row) row = table.NewRow() row("Id") = 2 row("Name") = "Lucy" table.Rows.Add(row) row = table.NewRow() row("Id") = 3 row("Name") = "Thomas" table.Rows.Add(row) Dim sql As String = "SELECT * FROM Friends2" Using da As New SqliteDataAdapter(sql, con) Using cb As New SqliteCommandBuilder(da) da.Fill(table) da.Update(table) End Using End Using con.Close() End Using End Sub End Module
In the example, we create a new DataTable
object. We add two columns and three rows to the table. Then we save the data in a new Friends2
database table.
Dim table As New DataTable("Friends2")
A new DataTable
object is created.
column = New DataColumn() column.DataType = System.Type.GetType("System.Int32") column.ColumnName = "Id" table.Columns.Add(column)
A new column is added to the table. We provide a data type and name for the column. The columns of a DataTable
are accessed via the Columns
property.
row = table.NewRow() row("Id") = 1 row("Name") = "Jane" table.Rows.Add(row)
A row is added to the table. The rows of a DataTable
are accessed via the Rows
property.
Dim sql As String = "SELECT * FROM Friends2" Using da As New SqliteDataAdapter(sql, con)
The SqliteDataAdapter
is an intermediary between the database table and its representation in the memory.
Using cb As New SqliteCommandBuilder(da)
The SqliteCommandBuilder
wraps the data adapter. It only needs to be instantiated. We do not work with it directly later.
da.Fill(table) da.Update(table)
The data adapter is filled with the data from the table. The Update
method inserts the data to the database.
Saving XML data
Data from the DataTable
can be easily saved in an XML file. There is a WriteXml()
method for this task.
Option Strict On Imports Mono.Data.Sqlite Imports System.Data Module Example Sub Main() Dim cs As String = "URI=file:test.db" Using con As New SqliteConnection(cs) con.Open() Dim stm As String = "SELECT * FROM Cars LIMIT 5" Using da As New SqliteDataAdapter(stm, con) Dim ds As New DataSet() da.Fill(ds, "Cars") Dim dt As DataTable = ds.Tables("Cars") dt.WriteXml("cars.xml") For Each row As DataRow In dt.Rows For Each col As DataColumn In dt.Columns Console.Write(row(col) & " ") Next Console.WriteLine() Next End Using con.Close() End Using End Sub End Module
We print 5 cars from the Cars
table. We also save them in an XML file.
Using da As New SqliteDataAdapter(stm, con)
A SqliteDataAdapter
object is created. It takes an SQL statement and a connection as parameters. The SQL statement will be used to retrieve and pass the data by the SqliteDataAdapter
.
Dim ds As New DataSet() da.Fill(ds, "Cars")
We create the DataSet
object. The Fill()
method uses the data adapter to retrieve the data from the data source. It creates a new DataTable
named Cars
and fills it with the retrieved data.
Dim dt As DataTable = ds.Tables("Cars")
The Tables
property provides us with the collection of data tables contained in the DataSet
. From this collection we retrieve the Cars
DataTable
.
dt.WriteXml("cars.xml")
We write the data from the data table to an XML file.
For Each row As DataRow In dt.Rows For Each col As DataColumn In dt.Columns Console.Write(row(col) & " ") Next Console.WriteLine() Next
We display the contents of the Cars
table to the terminal. To traverse the data, we utilise the rows and columns of the DataTable
object.
Loading XML data
We have shown how to save data in XML files. Now we are going to show, how to load the data from an XML file.
Option Strict On Imports Mono.Data.Sqlite Imports System.Data Module Example Sub Main() Dim cs As String = "URI=file:test.db" Using con As New SqliteConnection(cs) con.Open() Dim ds As New DataSet() ds.ReadXml("cars.xml") Dim dt As DataTable = ds.Tables("Cars") For Each row As DataRow In dt.Rows For Each col As DataColumn In dt.Columns Console.Write(row(col) + " ") Next Console.WriteLine() Next con.Close() End Using End Sub End Module
We read the contents of the cars.xml
file into the DataSet
. We print all the rows to the terminal.
Dim ds As New DataSet()
A DataSet object is created.
ds.ReadXml("cars.xml")
The data from the cars.xml
is read into the data set.
Dim dt As DataTable = ds.Tables("Cars")
When the data was read into the data set a new DataTable
was created. We get this table.
For Each row As DataRow In dt.Rows For Each col As DataColumn In dt.Columns Console.Write(row(col) + " ") Next Console.WriteLine() Next
We print all the rows of the data table.
$ mono loadxml.exe 1 Audi 52642 2 Mercedes 57127 3 Skoda 9000 4 Volvo 29000 5 Bentley 350000
Running the example.
DataGridView
In the next example, we are going to bind a table to a Winforms DataGridView
control.
Option Strict On Imports System.Windows.Forms Imports System.Drawing Imports System.Data Imports Mono.Data.Sqlite Public Class WinVBApp Inherits Form Private dgv As DataGridView Private da As SqliteDataAdapter Private ds As DataSet Public Sub New() Me.Text = "DataGridView" Me.Size = New Size(450, 350) Me.InitUI() Me.InitData() Me.CenterToScreen() End Sub Private Sub InitUI() dgv = New DataGridView() dgv.Location = New Point(8, 0) dgv.Size = New Size(350, 300) dgv.TabIndex = 0 dgv.Parent = Me End Sub Private Sub InitData() Dim cs As String = "URI=file:test.db" Dim con As New SqliteConnection(cs) Dim stm As String = "SELECT * FROM Cars" Using con As New SqliteConnection(cs) con.Open() ds = new DataSet() Using da As New SqliteDataAdapter(stm, con) da.Fill(ds, "Cars") dgv.DataSource = ds.Tables("Cars") End Using con.Close() End Using End Sub Public Shared Sub Main() Application.Run(New WinVBApp) End Sub End Class
In this example, we bind the Cars
table to the Winforms DataGridView
control.
Imports System.Windows.Forms Imports System.Drawing
These two namespaces are for the GUI.
Me.InitUI() Me.InitData()
Inside the InitUI()
method, we build the user interface. In the InitData()
method, we connect to the database, retrieve the data into the DataSe
and bind it to the DataGrid
control.
dgv = New DataGridView()
The DataGridView
control is created.
Dim stm As String = "SELECT * FROM Cars"
We will display the data from the Cars
table in the DataGridView
control.
dgv.DataSource = ds.Tables("Cars")
We bind the DataSource
property of the DataGridView
control to the chosen table.

In this part of the SQLite Visual Basic tutorial, we have worked with the DataSet
, DataTable
, SqliteDataAdapter
, SqliteCommandBuilder
, and DataGridView
classes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论