Imports System.IO
Imports System.Data.OleDb
Imports System.Drawing.Imaging
Public Class building
Public Enum AnimateWindowFlags
AW_HOR_POSITIVE = &H1
AW_HOR_NEGATIVE = &H2
AW_VER_POSITIVE = &H4
AW_VER_NEGATIVE = &H8
AW_CENTER = &H10
AW_HIDE = &H10000
AW_ACTIVATE = &H20000
AW_SLIDE = &H40000
AW_BLEND = &H80000
End Enum
Public Declare Auto Function AnimateWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal time As Integer, ByVal flags As AnimateWindowFlags) As Boolean
Sub animateWin(ByVal frmToAnimate As Form, ByVal showForm As Boolean)
If showForm Then
AnimateWindow(frmToAnimate.Handle, 1000, AnimateWindowFlags.AW_HOR_NEGATIVE Or AnimateWindowFlags.AW_SLIDE)
Else
AnimateWindow(frmToAnimate.Handle, 1000, AnimateWindowFlags.AW_HOR_POSITIVE Or AnimateWindowFlags.AW_HIDE)
End If
End Sub
Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =" & Application.StartupPath & "\MyDatabase.mdb"
Dim Conn As New OleDbConnection(ConStr)
Dim DataSet1 As New DataSet
Dim SQLstr As String = "SELECT * FROM t_bul"
Dim SQLstr2 As String = "SELECT * FROM Customer"
Dim rec As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height) 'create a new recatangle
Public edit As Boolean
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim conn, CON, con1 As New OleDbConnection(ConStr)
Dim DS As New DataSet
Dim cmd1 As New OleDbCommand
Dim DataAdapter1 As New OleDbDataAdapter
Dim dataset1, dataset2 As New DataSet
cbocity.Enabled = True
If Me.ComboBox1.SelectedIndex = 0 Then
cmd1.CommandText = "Select * From Capital"
cmd1.Connection = CON
CON.Open()
DataAdapter1.SelectCommand = cmd1
DataAdapter1.Fill(dataset1, "Capital")
CON.Close()
cbocity.DataSource = dataset1.Tables("Capital")
cbocity.DisplayMember = "location"
cbocity.ValueMember = "location"
ElseIf Me.ComboBox1.SelectedIndex = 1 Then
cmd1.CommandText = "Select * From Central"
cmd1.Connection = CON
CON.Open()
DataAdapter1.SelectCommand = cmd1
DataAdapter1.Fill(dataset1, "Central")
CON.Close()
cbocity.DataSource = dataset1.Tables("Central")
cbocity.DisplayMember = "location"
cbocity.ValueMember = "location"
ElseIf Me.ComboBox1.SelectedIndex = 2 Then
cmd1.CommandText = "Select * From Muharraq"
cmd1.Connection = CON
CON.Open()
DataAdapter1.SelectCommand = cmd1
DataAdapter1.Fill(dataset1, "Muharraq")
CON.Close()
cbocity.DataSource = dataset1.Tables("Muharraq")
cbocity.DisplayMember = "location"
cbocity.ValueMember = "location"
ElseIf Me.ComboBox1.SelectedIndex = 3 Then
cmd1.CommandText = "Select * From Northern"
cmd1.Connection = CON
CON.Open()
DataAdapter1.SelectCommand = cmd1
DataAdapter1.Fill(dataset1, "Northern")
CON.Close()
cbocity.DataSource = dataset1.Tables("Northern")
cbocity.DisplayMember = "location"
cbocity.ValueMember = "location"
ElseIf Me.ComboBox1.SelectedIndex = 4 Then
cmd1.CommandText = "Select * From southern"
cmd1.Connection = CON
CON.Open()
DataAdapter1.SelectCommand = cmd1
DataAdapter1.Fill(dataset1, "southern")
CON.Close()
cbocity.DataSource = dataset1.Tables("southern")
cbocity.DisplayMember = "location"
cbocity.ValueMember = "location"
End If
End Sub
Private Sub building_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
animateWin(Me, True)
Dim SQLstr3 As String = "SELECT * FROM tblPictures"
Conn.Open()
Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
Dim DataAdapter2 As New OleDbDataAdapter(SQLstr2, Conn)
Dim DataAdapter3 As New OleDbDataAdapter(SQLstr3, Conn)
DataAdapter1.Fill(DataSet1, "t_bul")
DataAdapter2.Fill(DataSet1, "Customer")
DataAdapter3.Fill(DataSet1, "tblPictures")
Conn.Close()
Me.txtrea.DataBindings.Add("text", DataSet1, "t_bul.RealestateNo")
Me.txtnum.DataBindings.Add("text", DataSet1, "t_bul.Serianumber")
Me.DateTimePicker1.DataBindings.Add("text", DataSet1, "t_bul.Date")
Me.ComboBox1.DataBindings.Add("text", DataSet1, "t_bul.Governorate")
Me.cbocity.DataBindings.Add("text", DataSet1, "t_bul.City")
Me.ComboBox2.DataBindings.Add("text", DataSet1, "t_bul.Transaction")
Me.txtclass.DataBindings.Add("text", DataSet1, "t_bul.Classification")
Me.txtbarea.DataBindings.Add("text", DataSet1, "t_bul.Buildingarea")
Me.txtvalue.DataBindings.Add("text", DataSet1, "t_bul.TotalValue")
Me.txtnote.DataBindings.Add("text", DataSet1, "t_bul.Note")
Me.PictureBox1.DataBindings.Add("text", DataSet1, "tblPictures.Picture")
Me.TextBox1.DataBindings.Add("text", DataSet1, "Customer.RealestateNo")
Me.txtname.DataBindings.Add("text", DataSet1, "Customer.Customer Name")
Me.txtcpr.DataBindings.Add("text", DataSet1, "Customer.CPR")
Me.txttelephone.DataBindings.Add("text", DataSet1, "Customer.Telephone")
Me.txtmobile.DataBindings.Add("text", DataSet1, "Customer.Mobile Phone")
Me.txtfax.DataBindings.Add("text", DataSet1, "Customer.Fax")
Me.txtemail.DataBindings.Add("text", DataSet1, "Customer.Email")
Me.txtaddress.DataBindings.Add("text", DataSet1, "Customer.Address")
Me.txtincome.DataBindings.Add("text", DataSet1, "Customer.Monthly income")
ChangePosition()
End Sub
Function ge()
Dim ImageData() As Byte
Dim MemoryStream As MemoryStream
Dim strSQL As String = String.Empty
Dim Con As New OleDb.OleDbConnection
Dim Cmd1 As New OleDb.OleDbCommand
Dim cn As New OleDb.OleDbConnection(ConStr)
Dim cmd As New OleDb.OleDbCommand("Select Picture From tblPictures ORDER BY Realestateno", cn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "tblPictures")
Dim c As Integer = ds.Tables("tblPictures").Rows.Count
If c > 0 Then
cn.Open()
Dim bytBLOBData() As Byte = _
ds.Tables("tblPictures").Rows(c - 1)("Picture")
ImageData = CType(cmd.ExecuteScalar, Byte())
If Not ImageData Is Nothing Then
MemoryStream = New IO.MemoryStream(ImageData)
Me.PictureBox1.Image = New Bitmap(MemoryStream)
End If
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.BindingContext(DataSet1, "t_bul").Position = 0
Me.BindingContext(DataSet1, "Customer").Position = 0
ChangePosition()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.BindingContext(DataSet1, "t_bul").Position += 1
Me.BindingContext(DataSet1, "Customer").Position += 1
ChangePosition()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.BindingContext(DataSet1, "Customer").Position = Me.BindingContext(DataSet1, "Customer").Count - 1
Me.BindingContext(DataSet1, "t_bul").Position = Me.BindingContext(DataSet1, "t_bul").Count - 1
ChangePosition()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.BindingContext(DataSet1, "t_bul").Position -= 1
Me.BindingContext(DataSet1, "Customer").Position -= 1
ChangePosition()
End Sub
Public Sub ChangePosition()
If Me.BindingContext(DataSet1, "t_bul").Position = -1 Then
Label1.Text = "Record 0 from 0 "
Button3.Enabled = False
Button2.Enabled = False
Else
Label1.Text = "Record " & Me.BindingContext(DataSet1, "t_bul").Position + 1 & _
" from " & Me.BindingContext(DataSet1, "t_bul").Count
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Close()
End Sub
End Class
the picture is not chanage
please help me to solve that
i have table building
customer
tblpicture
table building contain the buildin information
table costomer conrian the customer information
table picture conrian the Picture
i save these information from anther form but when i binding the data
and click next button the picture dont change please help me
Are you using VB 2005 or later? If so then your code is rather more complex than necessary. You should populate a DataTable with your data and bind it to a BindingSource, then bind that to your controls. You can then call MoveNext, etc. on the BindingSource.
You can't bind the PictureBox so you'll have to update that manually. You need to do a bit of fancy footwork to manage the MemoryStream though, because you'll have to create it when you display one Image and then destroy it when you display the next. You would update the PictureBox on the CurrentChanged event of the BindingSource and the code should look something like this:
vb.net Code:
Private imageSource As MemoryStream
Private Sub BindingSource1_CurrentChanged(ByVal sender As Object, _
ByVal e As EventArgs) Handles BindingSource1.CurrentChanged
If Me.PictureBox1.Image IsNot Nothing Then
'Destroy the existing objects.
Me.PictureBox1.Image.Dispose()
Me.imageSource.Dispose()
Me.PictureBox1.Image = Nothing
End If
Dim data As DataRowView = DirectCast(Me.BindingSource1.Current, DataRowView)
If data IsNot Nothing Then
'Create new objects.
Me.imageSource = New MemoryStream(DirectCast(data("Picture"), Byte()))