Public Shared Function ByteToImage(blob As Byte()) As Bitmap
Dim mStream As New MemoryStream()
Dim pData As Byte() = blob
mStream.Write(pData, 0, Convert.ToInt32(pData.Length))
Dim bm As New Bitmap(mStream, False)
mStream.Dispose()
Return bm
End Function
Imports System.Data.OleDb
Imports System.String
Imports System.IO
Public Class Form1
Dim CurrentRow As Integer
Dim con As New OleDbConnection
Dim dad As OleDbDataAdapter
Dim dst As New DataSet
Dim cmd As OleDbCommand
Dim bs As New BindingSource
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CurrentRow = 0
Dim strconnaccess2007 As String = "Provider=Microsoft.ACE.OLEDB.12.0;data source=dormitory.accdb"
With con
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconnaccess2007
.Open()
End With
Dim sqlcustomer As String
sqlcustomer = "select * from student"
dad = New OleDbDataAdapter(sqlcustomer, con)
dad.Fill(dst, "student")
dad.SelectCommand.CommandText = sqlcustomer
bs.DataSource = dst.Tables("student")
End Sub
Public Shared Function bytetoimage(ByVal blob As Byte()) As Bitmap
Dim mStream As New MemoryStream()
Dim pdata As Byte() = blob
mstream.write(pdata, 0, Convert.ToInt32(pdata.Length))
Dim bm As New Bitmap(mstream, False)
mstream.dispose()
Return bm
End Function
Private Sub ShowData(ByVal CurrentRow)
Try
txtstudentid.Text = dst.Tables("student").Rows(CurrentRow)("studentid")
txtName.Text = dst.Tables("student").Rows(CurrentRow)("name-surname")
cobsex.Text = dst.Tables("student").Rows(CurrentRow)("sex")
DateTimePicker1.Text = dst.Tables("student").Rows(CurrentRow)("birthday")
txtpeopleid.Text = dst.Tables("student").Rows(CurrentRow)("peopleid")
cobgraduate.Text = dst.Tables("student").Rows(CurrentRow)("graduate")
cobfaculty.Text = dst.Tables("student").Rows(CurrentRow)("faculty")
cobdepartment.Text = dst.Tables("student").Rows(CurrentRow)("department")
txtTel.Text = dst.Tables("student").Rows(CurrentRow)("telephone")
PictureBox1.Image = Image.FromFile(dst.Tables("student").Rows(CurrentRow)("photo"))
Catch ex As Exception
End Try
End Sub
Private Sub ExitNow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitNow.Click
Con.Close()
Me.Close()
End
End Sub
Private Sub First_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles First.Click
CurrentRow = 0
ShowData(CurrentRow)
End Sub
Private Sub Previous_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Previous.Click
If CurrentRow <> 0 Then
CurrentRow -= 1
ShowData(CurrentRow)
Else
MsgBox("First Record is Reached!!!")
End If
End Sub
Private Sub Forward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Forward.Click
If CurrentRow = dst.Tables("student").Rows.Count - 1 Then
MsgBox("Last Record is Reached!!!")
Else
CurrentRow += 1
ShowData(CurrentRow)
End If
End Sub
Private Sub Last_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Last.Click
CurrentRow = dst.Tables("student").Rows.Count - 1
ShowData(CurrentRow)
End Sub
Private Sub Clear()
txtstudentid.Text = ""
txtName.Text = ""
txtpeopleid.Text = ""
txtTel.Text = ""
End Sub
Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search.Click
Dim SearchId As Integer
Dim i, j As Integer
If CheckId() = False Then
MsgBox("Integer Value Required!!!")
Exit Sub
End If
Try
SearchId = txtstudentid.Text
j = dst.Tables("student").Rows.Count - 1
i = 0
While i <> j + 1
If SearchId = dst.Tables("student").Rows(i)("studentid") Then
ShowData(i)
Exit While
ElseIf i = j Then
Clear()
MsgBox("Record Not Found!!!")
ShowData(CurrentRow)
Exit While
End If
i += 1
End While
CurrentRow = i
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Function CheckId()
Try
If IsNumeric(txtstudentid.Text) = False Then
ShowData(CurrentRow)
txtstudentid.Focus()
Return False
End If
Catch ex As Exception
End Try
Return True
End Function
Private Function IsIdExist()
Dim Str, Str1 As String
Dim i As Integer
Str = txtstudentid.Text
i = 0
While i <> dst.Tables("student").Rows.Count
Str1 = dst.Tables("student").Rows(i)("studentid")
If Str = Str1 Then
Return True
End If
i += 1
End While
Return False
End Function
End Class