display image with navigation

how to display images using picture1.image with navigation

Page 1 of 1

2 Replies - 2059 Views - Last Post: 03 November 2009 - 06:40 AM Rate Topic: -----

#1 chandukush  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-October 09

display image with navigation

Posted 26 October 2009 - 06:08 AM

hi all
I am new to vb.net i want to display images.but the problem is navigation code is improper.pls help me.

 Public Sub showimage()
		On Error GoTo fix
	   
		Dim sql As String = "SELECT CUST_IMAGE FROM form2 WHERE FULL_NAME='" & Label2.Text & "'"
		DBcon.Open()
		Dim cmd As OleDbCommand = New OleDbCommand(sql, DBcon)
	 
		Dim b() As Byte
		b = cmd.ExecuteScalar()
		If (b.Length > 0) Then
			Dim stream As New MemoryStream(b, True)
			stream.Write(b, 0, b.Length)
			'Display image
			PictureBox1.Image = New Bitmap(stream)
			stream.Close()
		End If
		DBcon.Close()
fix:
		Exit Sub
	End Sub

Navigating images code
Dim DBcon As OleDb.OleDbConnection
	Dim Dbcom As New OleDb.OleDbCommand()
	Dim Dbadap As New OleDb.OleDbDataAdapter()
	Dim Dbset As New DataSet()
	Dim Nextb As Long
	Dim PrevB As Long
	Dim TotalC As Long
	Public Sub ShowData()
		Nextb = 0
		PrevB = 0
		Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\MMTS_DB.mdb"
		Try
			DBcon = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;data source=" & Application.StartupPath & "\MMTS_DB.mdb;jet oledb:database password=Kaila@123")
			Dbcom = New OleDbCommand("Select FULL_NAME,CUST_IMAGE from form2 where CUST_ID <>null order by CUST_ID asc")
			DBcon.Open()
		Catch ex As Exception
			MsgBox(ex.Message, MsgBoxStyle.Information, "MMTS Project Connection")
			End
		End Try
		Dbcom.Connection = DBcon
		Dbadap = New OleDb.OleDbDataAdapter("Select FULL_NAME,CUST_IMAGE from form2 where CUST_ID <>null order by CUST_ID asc", DBcon)
		Dbset = New DataSet("MS")
		Dbadap.Fill(Dbset, "MS")
		Dim x = Dbset.Tables("MS").Rows.Count()
		TotalC = x - 1
		FILL(0)
		DBcon.Close()
	End Sub

	Private Sub FILL(ByVal X As Long)
		If Dbset Is Nothing Then Return
		Try
			With Dbset.Tables("MS").Rows(X)
				Label2.Text = IIf(IsDBNull(.Item("FULL_NAME")), "NULL", .Item("FULL_NAME"))
showimage()
			End With
		Catch err As Exception
			MsgBox(err.Message, MsgBoxStyle.Information, "MMTS PROJECT Dataset")
		End Try

	End Sub



Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: display image with navigation

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: display image with navigation

Posted 26 October 2009 - 07:48 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: display image with navigation

Posted 03 November 2009 - 06:40 AM

Hi,

Here is one Problem

b = cmd.ExecuteScalar()



the ExecuteScalar does not return actual data from the database.

You will need to use a OleDBReader or DataTable to get to that data.....

Like this

		Dim objReader As System.Data.OleDb.OleDbDataReader

		Dim sql As String = "SELECT CUST_IMAGE FROM form2 WHERE FULL_NAME='" & Label2.Text & "'"
		DBcon.Open()
		Dim cmd As OleDbCommand = New OleDbCommand(sql, DBcon)
	 
		Dim b() As Byte
		objReader = .ExecuteReader
		if objReader.HasRows = True then
			 objReader.Read()
			 b = objReader("CUST_IMAGE")
			 If (b.Length > 0) Then
				Dim stream As New MemoryStream(b, True)
				stream.Write(b, 0, b.Length)
				'Display image
				PictureBox1.Image = New Bitmap(stream)
				stream.Close()
			End If
		End If
		objReader.Close()
		DBcon.Close()


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1