|
Hi Jason,
Please know that Images are stored in database as BLOB short for Binary Large OBject, a collection of binary data stored as a single entity in a database management systems (DBMS). BLOBs are used primarily to hold multimedia objects such as images, videos, and sound, though they can also be used to store programs or even fragments of code. Not all DBMSs support BLOBs.
Therefore, to read or write an image we need to use array of Byte. Below is a code snippet to read an image from a database and to show it on a picture box.
----------------------------------------------------------------------------------------------------
BEGIN CODE
' Construct a SQL string and a connection object
Dim sql As String = "SELECT UserPhoto FROM Users"
Dim conn As OleDbConnection = New OleDbConnection
conn.ConnectionString = connectionString
' Open connection
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
Dim fs As FileStream
Dim bw As BinaryWriter
Dim bufferSize As Integer = 300000
Dim outbyte(300000 - 1) As Byte
Dim retval As Long
Dim startIndex As Long = 0
Dim pub_id As String = ""
Dim reader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)
' Read first record
reader.Read()
fs = New FileStream(savedImageName, FileMode.OpenOrCreate, FileAccess.Write)
bw = New BinaryWriter(fs)
startIndex = 0
retval = reader.GetBytes(0, 0, outbyte, 0, bufferSize)
bw.Write(outbyte)
bw.Flush()
' Close the output file.
bw.Close()
fs.Close()
reader.Close()
' Display image
curImage = Image.FromFile(savedImageName)
PictureBox1.Image = curImage
PictureBox1.Invalidate()
' Clean up connection
If conn.State = ConnectionState.Open Then
conn.Close()
' Dispose connection
conn.Dispose()
End If
End Sub
END CODE
----------------------------------------------------------------------------------------------------
Hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Hi John-
Thanks for replying back. I have some questions about your code.
My connection setup is all done on the GUI side (using Dataset, bindingsource, and bindingnavigator). What I am doing is loading my data on startup of my app...my data loads fine (including the picbox) and the app is working great. What I was trying to do is create a checkbox on the form that, when checked, would parse the data out to display only the information in my new dataset, connectionstring, and query. And when unchecked, it would go back to its original state.
I got all that to work as well except for in the picbox. What I am doing is clearing all the databinding and then manually re-binding the data in the code. Everything updates when I do this except for the picbox.
Now to my question
I am using the code you provided and things needed modified but I am getting an error on "curImage". Can you elaborate on this part? I will provide your code again...you can then see the changes that were necessary to make (but may not be knowing that my connection setup is fine).
'Construct a SQL string and a connection object
Dim sql As String = "SELECT PK, FName, LName, CO, Street, City, State, Zip, Zip2, Email, SentDate, Sent, ReceivedDate, Received, Notes, Location, AddySource, Success, RTS, Fee, Preprint, Profession, TypedLetter, Picture, International, SentEmail FROM(ADDRESSES)WHERE(Success = 'Success')ORDER BY LName"
Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\jasons\Desktop\Autographs\bin\Autographs.mdb"
' Open connection
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql, conn)
Dim fs As FileStream
Dim bw As BinaryWriter
Dim bufferSize As Integer = 300000
Dim outbyte(300000 - 1) As Byte
Dim retval As Long
Dim startIndex As Long = 0
Dim pub_id As String = ""
Dim reader As OleDb.OleDbDataReader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)
' Read first record
reader.Read()
fs = New FileStream("Picture", FileMode.OpenOrCreate, FileAccess.Write)
bw = New BinaryWriter(fs)
startIndex = 0
retval = reader.GetBytes(0, 0, outbyte, 0, bufferSize)
bw.Write(outbyte)
bw.Flush()
' Close the output file.
bw.Close()
fs.Close()
reader.Close()
' Display image
curImage = Image.FromFile("Picture")
picImage.Image = curImage
picImage.Invalidate()
Thanks,
jason
I'd rather have a bottle in front of me than a frontal lobotomy.
|
|
|
|
|
Hi All,
i have set date format to dd/MM/yyyy in my application developed in vb.net. i don't know what will the system date format of my client'pc, so i want to set the date format of my client's pc according to my application's settings and restore its original settings when my application closed. all this i want at run time in vb.net.
thanks
|
|
|
|
|
Hi,
I would suggest you to try the following code snippet to change the date format of the system.
-----------------------------------------------------------------------------------------------
BEGIN CODE
Imports Microsoft.Win32
Dim reg As RegistryKey
reg = Registry.Users.OpenSubKey("S-1-5-21-1757981266-861567501-682003330-500\Control Panel\International", True)
If Convert.ToString(reg).Trim = String.Empty Then
MsgBox("Blank")
Else
reg.SetValue("sShortDate", "dd/MM/yyyy")
reg.SetValue("sLongDate", "dd/MM/yyyy")
End If
END CODE
-----------------------------------------------------------------------------------------------
Hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
DON'T.
In your application, display the date in whatever format that you like, using ToString(formatstring), but _don't_ change the machine date time format.
|
|
|
|
|
I agree. Just change the display format, but not how the machine is set. Changing machine settings too much can be dangerous and probably piss off user.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
hi every body
i want to change the start up form name according to the user choice he choose the form name from combo box and then suppose to save his choice in Application.myapp in the main form element , How Can i do that ???
Thanks
Mona
LA ELAH ELA ALLAH MOHAMED RASOL ALLAH
|
|
|
|
|
I have written a macro in XL VBA that at the touch of a button will copy two of the worksheets from a "Master" to a new worksheet, and then will save that worksheet by a unique name made from concatenation of several cells.
(it is a Purchase order, consists of Sitecode, Suppliercode and unique index number, these then form the name of the file, which is the Order Number, ie PUL-CAT01-001)
I know it is possible at this point to save the file to a SPECIFIC LOCATION, ie have the path set up so that it will save to a subdirectory based on the Site.
Damned if I can work out how to do this. I have spent quite some time looking around at various VBA sites, but alas seem incapable of locating anything like what I need.
Does anyone know of a site where I can be helped? or possibly suggest the line of code that needs to replace what is currently just a generic save into the top level directory?
I wouldn't ask, I would normally try to solve this, but time constraints and a certain ennui involved in looking at loads of VBA sites that help everything else but this have eroded my patience.
All and any help gratefully accepted!
------------------------------------
I try to appear cooler,
by calling him Euler.
|
|
|
|
|
AFAIK, the Workbook.SaveAs function takes a fully qualified path name argument.
|
|
|
|
|
hi,
i have search all about tcplistener, but many of the sample is about using console application, i am using windows application for vb.net want to create TCPListener server application, did anyone can tell about any reference of example in using TCPListener windows application.
please..
|
|
|
|
|
if you have vs2003 installed, you will find a sample app in the folder below,
"Program Files\Microsoft Visual Studio .NET 2003\Vb7\VB Samples"
else
send me your mail address and i will send you the app
thanks
Anoop
|
|
|
|
|
hai friends
i m using TableLayoutPanel control in my project to add the images and the corresponding indexes to it.
i can add to TableLayoutPanel control ...
the problem ...
it differs the direction ...
i.e
it is adding the images in the direction like this ..
<-------- / end of the Table Layout panel
2 1
i.e it is adding the images from the end of the TableLayoutPanel
plz help me ....
i need to add the images like this ------->
plz help
thanks in advance
vijay
devulapally_vijay@yahoo.co.in
|
|
|
|
|
Hello,
I am working in VB.NET (VS2005)
I need to disabled an item in CheckedListBox.
I know that I have to do as following: chk.items(No).enabled=false.
But in my case it is a little different:
Here is my code:
'In Form1
chk.Items.Add(New clsItem(ID1, Name1))
chk.Items.Add(New clsItem(ID2, Name2))
chk.Items.Add(New clsItem(ID3, Name3))
'Class
Public Class clsItem
Private ID As Integer, Name As String
Public Sub New(ByVal _ID As Integer, ByVal _Name As String)
ID = _ID
Name = _Name
End Sub
Public Overrides Function ToString() As String
Return Name
End Function
Property ItemID() As Integer
Get
Return ID
End Get
Set(ByVal value As Integer)
ID = value
End Set
End Property
Property ItemName() As String
Get
Return Name
End Get
Set(ByVal value As String)
Name = value
End Set
End Property
End Class
How can I disable one of my items now?
Thank you
Shay Noy
|
|
|
|
|
Hello,
Shay, if you need to disable only single item in the CheckedListBox, you can then try using
the ItemCheck() event of CheckedListBox. For example, in the given code snippet, I have disabled
the second item in the list.
<br />
Private Sub chk_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles chk.ItemCheck<br />
<br />
If e.Index = 1 Then<br />
<br />
e.NewValue = e.CurrentValue<br />
<br />
End If<br />
<br />
End Sub<br />
You can manipulate it more, by taking a global variable which will hold the index of the row to be
disabled. You can match that variable value with the e.index to decide at runtime which rows to be
disabled.
I hope this will help you.
Regards,
Allen
Allen Smith
Software Engineer
ComponentOne LLC
www.componentone.com
|
|
|
|
|
Thank you, this is a good idea, I will use it.
Does anybody know how to solve it by really disabling the checkbox item as I ask in my first message?
Thank you
Shay Noy
|
|
|
|
|
Hi all!
I'm trying to do a pretty simple thing in VB6, but it's not working!
In the main form:
Sub Command1_Click()
Dim cls1 As New Class1
cls1.fnc1 StatusBar1.SimpleText
end sub
And in Class1:
Function fnc1(ByRef logText As String)
Dim i as Integer
For i=0 To 10
logText = "We're at number " & i
Next
End Function
I though this would update the statusbar text in real time, but it doesn't work!
Anyone knows why?
|
|
|
|
|
Because
Gadjuka wrote: Dim cls1 As New Class1
creates a new Class1, which has no bearing on the instance of Class1 that is running.
Also, why on earth are you still using VB6 ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Well...some of our customers still have old VB6 applications. Sooner or later we'll upgrade them to .NET, but it takes time...
I tried the same thing in .NET by the way. There I get "A property or indexer may not be passed as an out or ref parameter", so this particular problem doesn't seems to be solved by upgrading.
|
|
|
|
|
The status bar will contain only the text that is returned by the function - which will be "We're at number 10" since that is when the function call returns to the called procedure.
|
|
|
|
|
Hi Gadjuka,
I think the error message you got when you tried to do this in .Net answers the 'Why' your code doesn't work.
'I tried the same thing in .NET by the way. There I get "A property or indexer may not be passed as an out or ref parameter", so this particular problem doesn't seems to be solved by upgrading. '
So maybe the solution is pretty similar to what you already have. Try this:
<br />
Sub Command1_Click() <br />
Dim cls1 As New Class1 <br />
cls1.fnc1 StatusBar1<br />
end sub<br />
<br />
<br />
Function fnc1(ByRef sb As StatusBar) <br />
Dim i as Integer <br />
<br />
For i=0 To 10 <br />
sb.SimpleText = "We're at number " & i <br />
Next<br />
End Function<br />
<br />
You should be able to pass a reference of the control - I'm pretty sure I've done something along these lines way back when I was doing VB6. I didn't test this but I'm pretty sure it will work. Good luck!
The #1 Reply when developers programs don't work: "I thought I fixed that"
|
|
|
|
|
Yepp, that works.
Problem is that I wanted it to be a bit more flexible. To be able to get a log text out from the function whether you want to continuously track the function's progress in the statusbar or write the information to a file.
But I guess this way of doing it (sending in statusbar.simpletext) isn't possible...
I achieved what I wanted by sending in an ordinary string as ref and then have a timer that checks that variable and updates the statusbar.
|
|
|
|
|
So pass a flag along with your status bar control to indicate you want to write to the log file, the statusbar or both and write the code to handle the log file in your Class1 class. Then you could call it from your method. Just a thought.
Glad you got it to work in any case, I've rarely found cases where you couldn't find some kind of way to solve the problem. Of course that's why we're software developers - because we like that sort of thing. Cheers!
The #1 Reply when developers programs don't work: "I thought I fixed that"
|
|
|
|
|
hi
my problem is:-
I want when user enter a url of a web site in textbox and when he clicks a button then its HTML code gets append in a textbox.How to implement it?
I have searched google. but i didn't get the answer
please help me
note: i dont want to use web browser control for this purpose.
I M using vb.net 2005
|
|
|
|
|
Try this :-
Dim URL As String = "http://www.codeproject.com"<br />
Dim oWebClient As New System.Net.WebClient()<br />
Dim sHtml as String<br />
sHtml = New System.Text.UTF8Encoding().GetString(oWebClient.DownloadData(URL))
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
i am making a software on Invoice Management system.i have a problem on data report
because report big than a4 size (Invoice is preprinted one)
so my query is
can i increse size of paper more than a4 and less than a4
how i do it in vb.
|
|
|
|
|