SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
Visual Basic 2008

Getting Start with Microsoft Visual Basic 2008

E-mail Print PDF

If you already know how to program in Visual Basic 6 then you will be able to move quickly into Visual Basic 2008. The below video show you:
- How to create project in Microsoft Visual Basic 2008?
- How to create new form in Microsoft Visual Basic 2008?
- Where is the project folder?


Download Video Here

 

How to Save Image into Table in Microsoft Access Using VB 2008

E-mail Print PDF

Please follow the instruction below:

  • Step 1: Create Database in Microsoft Access
    • Database: data.mdb
    • Create Table: tblstudent(stdid: Number, name: text, photo: OLE Object)
  • Step 2: Create Visual Basic 2008 Project
    • Create and Save Project in Visual Basic 2008
    • Put the database file (data.mdb) in the project execution folder (\bin\debug\)
    • Create Form named: frmStudent (view as the following image)

  • Step 3: Write Code in Visual Basic 2008
    On Click [Button Add]
    Dim cn As New OleDb.OleDbConnection
    cn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" & _
                          Application.StartupPath & "\data.mdb"
    cn.Open()
    
    Dim arrImage() As Byte
    Dim strImage As String
    Dim myMs As New IO.MemoryStream
            '
    If Not IsNothing(Me.picPhoto.Image) Then
         Me.picPhoto.Image.Save(myMs, Me.picPhoto.Image.RawFormat)
         arrImage = myMs.GetBuffer
         strImage = "?"
    Else
         arrImage = Nothing
         strImage = "NULL"
    End If
    
    Dim myCmd As New OleDb.OleDbCommand
    myCmd .Connection = cn
    myCmd .CommandText = "INSERT INTO tblstudent(stdid, [name], photo) " & _
                      " VALUES(" & Me.txtID.Text & ",'" & _
                      Me.txtName.Text & "'," & strImage & ")"
    If strImage = "?" Then
          myCmd.Parameters.Add(strImage, OleDb.OleDbType.Binary).Value = arrImage
    End If
    
    MsgBox("Data save successfully!")
    myCmd .ExecuteNonQuery()
    cn.Close()
    


    On Click [Button Search]
    Dim cn As New OleDb.OleDbConnection
    cn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; " & _
                         " Data Source=" & Application.StartupPath & "\data.mdb"
    cn.Open()
    
    Dim arrImage() As Byte
    Dim myMS As New IO.MemoryStream
    Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM tblstudent " & _
                                         " WHERE stdid=" & Me.txtID.Text, cn)
    Dim dt As New DataTable
    da.Fill(dt)
    
    If dt.Rows.Count > 0 Then
         Me.txtName.Text = dt.Rows(0).Item("name") & ""
         If Not IsDBNull(dt.Rows(0).Item("photo")) Then
                arrImage = dt.Rows(0).Item("photo")
                For Each ar As Byte In arrImage
                        myMS.WriteByte(ar)
                Next
                    '
                Me.picPhoto.Image = System.Drawing.Image.FromStream(myMS)
          End If
          Me.btnAdd.Enabled = False
    Else
          MsgBox("Record not found!")
    End If
    
    cn.Close()
    


Download Sample Code Here

 

How to Connect from VB 2008 to Microsoft Access 2003

E-mail Print PDF

This sample code is programmed in Visual Basic 2008 shows you how to connect to Microsoft Access 2003 (*.mdb) from Visual Basic 2008. In this sample, database file (data.mdb) is located in the project folder (..\bin\debug\data.mdb).

Dim Cnn As New OleDb.OleDbConnection()
Cnn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; " & _
                       "Data Source=" & Application.StartupPath & "\data.mdb;" & _
                       "Persist Security Info=False;"
Cnn.Open()

MsgBox("Connection established!")
 

How to Connect from VB 2008 to Microsoft Access 2007

E-mail Print PDF

This sample code is programmed in Visual Basic 2008 shows you how to connect to Microsoft Access 2007 (*.accdb) from Visual Basic 2008. Database file (data.accdb) is placed in the project folder (..\bin\debug\data.accdb).

Dim Cnn As New OleDb.OleDbConnection()
Cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; " & _
                       "Data Source=" & Application.StartupPath & "\data.accdb;" & _
                       "Persist Security Info=False;"
Cnn.Open()

MsgBox("Connection established!")
Download Sample Code Here
 

* Note: If you have problem with Access Database Engine from running the above code please download the below link:
1. For Microsoft Access 2007 Click Here
2. For Microsoft Access 2010 Click Here

 


Page 6 of 6