By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

How to browse MDB file in DataGridView and TIF Images in ImageViewer?

P: 9
Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Data
  3. Imports System.Data.OleDb
  4. Imports Microsoft.VisualBasic
  5.  
  6.  
  7. Public Class CARD_DECK_ENTRY Public myConString As String Dim con As New OleDb.OleDbConnection Dim myStream As Stream = Nothing
  8.  
  9. Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
  10.     End
  11.     Operator_ID.Close()
  12. End Sub
  13.  
  14. Private Sub OpenFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFileToolStripMenuItem.Click
  15.  
  16.     Dim openFileDialog1 As New OpenFileDialog()
  17.  
  18.     openFileDialog1.InitialDirectory = "c:\"
  19.     openFileDialog1.Filter = "mdb files (*.mdb)|*.mdb|All files (*.*)|*.*"
  20.     openFileDialog1.FilterIndex = 1
  21.     openFileDialog1.RestoreDirectory = True
  22.  
  23.  
  24.     If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
  25.         Try
  26.             myStream = openFileDialog1.OpenFile()
  27.             If (myStream IsNot Nothing) Then
  28.                 myConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & openFileDialog1.FileName
  29.                 Dim x As String = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.Length - 20) & "Images"
  30.                 con.ConnectionString = myConString
  31.                 con.Open()
  32.  
  33.                 datagridshow()
  34.             End If
  35.         Catch Ex As Exception
  36.             MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
  37.         Finally
  38.             ' Check this again, since we need to make sure we didn't throw an exception on open. 
  39.  
  40.             If (myStream IsNot Nothing) Then
  41.                 myStream.Close()
  42.             End If
  43.         End Try
  44.     End If
  45.  
  46. End Sub
  47.  
  48.  
  49. Private Sub CARD_DECK_ENTRY_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  50.  
  51.     con.ConnectionString = myConString
  52.  
  53.     con.Open()
  54.  
  55.     datagridshow()
  56.  
  57. End Sub
  58.  
  59. Private Sub datagridshow()
  60.     Dim ds As New DataSet
  61.     Dim dt As New DataTable
  62.     ds.Tables.Add(dt)
  63.     Dim da As New OleDbDataAdapter
  64.  
  65.     da = New OleDbDataAdapter("Select * from Data001", con)
  66.     da.Fill(dt)
  67.  
  68.     DataGridView1.DataSource = dt.DefaultView
  69.  
  70.     con.Close()
  71.  
  72.  
  73. End Sub
---

The above codes was to browse an MDB file and it worked, but now i'm about to load the images into a imageViewer with same time on browsing mdb. As you can see in the above codes, there was ("Select * from Data001", con) because it was a table I will be showing on the DataGridView. On the database there was a two table, those are "CardDeck" and "Data001." In CardDeck there was a "Image001" column. This column contains tif image names. On the folder where the database was found there was another folder on the same path(path of the database folder) named "Images". The column value of "Image001" will be found there. My point is how can I browse those "Image001" column value to a ImageViewer where those value are located in Folder "Images"? Please help. :'(
Jan 28 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.