Tag Archives: DataGridView

Connect to IBM DB2 & Read Image Column Using VB.Net

IBM DB2 LUW or DB2 Linux Unix Windows is one of a recommended RDBMS software used by many organizations.
By its name this DB2 LUW is a platform independent because it can be run on Linux, Windows, Solaris, Mac OS.

IBM has free version of DB2 LUW which is DB2 Express-C. Unlike another RDBMS, DB2 Express-C does not have any time restrictions or database size limitations.
So this free version can be used in production environment.

Because of platform independent we can install DB2 server on Linux as database server to avoid virus infection. Since MS Windows is more widely used (at least in my country) then we also can use MS Windows to run client application (VB.Net) that connect to DB2.
I will show you example using VB.Net to work with DB2 and also to get image data.

DB2 .Net Data Provider

IBM provides .Net Data Provider for DB2. It is located on installation of DB2 folder like C:\Program Files\IBM\SQLLib\Bin\netf20\IBM.Data.DB2.dll. I added this library file to project’s reference.
I use DB2Connection class to establish connection to DB2. DB2DataAdapter to retrieve recordset and DB2Command to execute sql query.

Example

I use SAMPLE database and populate DataGridView with Employee data. If employee has a photo then it will be showed on picture box.
Please refer to this pic below:


Continue reading

Fill DataGridView and cancel process using DataAdapter and BackgroundWorker

Introduction

Filling data to DataGridView with SqlDataAdapter is a common task but to cancel it in the middle of fill process need a tricky way. Especially when SqlDataAdapter returning large DataSet then no progress status informed to user since SqlDataAdapter need time to fetch DataSet. Also this project does not need to have button like “More records” to fetch more dataset. We can retrieve as much records you like and cancel it any time.

Background

We need to show records immediately and user can cancel the retrieval process whenever they like. The basic idea is using int recordcount = SqlDataAdapter.Fill(int startrow, int maxrecords, DataTable dt) method at BackgroundWorker.DoWork event. That Fill method is similar to paging in web page. BackgroundWorker execute SqlDataAdapter.Fill in loop until it has no more record to fetch and we can cancel the process before or after SqlDataAdapter.Fill. Continue reading