Click here to Skip to main content
15,887,135 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: help sending a form to bottom Pin
f6414-May-04 7:51
f6414-May-04 7:51 
Generalsending email base on radiobuttonlist selection Pin
devgeez14-May-04 5:49
devgeez14-May-04 5:49 
GeneralRe: sending email base on radiobuttonlist selection Pin
Mike Ellison14-May-04 6:34
Mike Ellison14-May-04 6:34 
GeneralRe: sending email base on radiobuttonlist selection Pin
devgeez21-May-04 3:41
devgeez21-May-04 3:41 
GeneralRe: sending email base on radiobuttonlist selection Pin
Mike Ellison21-May-04 4:21
Mike Ellison21-May-04 4:21 
GeneralRe: sending email base on radiobuttonlist selection Pin
devgeez21-May-04 4:31
devgeez21-May-04 4:31 
GeneralRe: sending email base on radiobuttonlist selection Pin
Mike Ellison21-May-04 6:28
Mike Ellison21-May-04 6:28 
GeneralFile Stream Headache Pin
BMS581914-May-04 5:01
BMS581914-May-04 5:01 
I have a two form project. Form1 has one button on it with two lines of code:

Dim f_form2 As New Form2
f_form2.ShowDialog()

Form2 reads in a .JPG from SQL Server and displays the .JPG in a picture box on Form2. All this works great UNTIL I close Form2 and call it a second time. Form2 blows up with the following message:

An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The process cannot access the file "C:\pic.jpg" because it is being used by another process.


If I close down the whole app and restart it, it's fine until the second call to Form2, so I'm obviously not releasing something correctly but don't know what to try. Help!

Thanks in advance.

*** here's the code ****
<br />
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
        Dim fs As New FileStream("C:\pic.jpg", FileMode.Create, FileAccess.Write) 'blows up here second time form is called<br />
        Dim bw As New BinaryWriter(fs)<br />
<br />
        Dim Buffersize As Integer = 16384<br />
        Dim Outbyte(Buffersize - 1) As Byte<br />
        Dim retval As Long<br />
        Dim startindex As Long = 0<br />
        Dim actualsize As Integer<br />
<br />
        Dim ConString As String<br />
        ConString = ("Persist Security Info=False;Integrated Security=SSPI;Data Source=(local);Database=db")<br />
<br />
        Dim strSQLCommand As String<br />
        strSQLCommand = "select blob_segment from blob where picid = 574739053"<br />
<br />
        Dim Connection As New SqlConnection(ConString)<br />
<br />
        Dim Command As New SqlCommand(strSQLCommand, Connection)<br />
<br />
        Connection.Open()<br />
        Dim Reader As SqlDataReader = Command.ExecuteReader(CommandBehavior.SequentialAccess)<br />
<br />
        actualsize = 0<br />
<br />
        Do While Reader.Read<br />
            startindex = 0<br />
<br />
            retval = Reader.GetBytes(0, startindex, Outbyte, 0, Buffersize)<br />
<br />
            Do While retval = Buffersize<br />
                MsgBox(Str(Buffersize))<br />
                bw.Write(Outbyte)<br />
                bw.Flush()<br />
                startindex += Buffersize<br />
                retval = Reader.GetBytes(0, startindex, Outbyte, 0, Buffersize)<br />
            Loop<br />
<br />
            bw.Write(Outbyte, 0, CInt(retval))<br />
            bw.Flush()<br />
            fs.Flush()<br />
            bw.Close()<br />
            fs.Close()<br />
<br />
        Loop<br />
<br />
        Reader.Close()<br />
        Connection.Close()<br />
<br />
        PictureBox1.Image = Image.FromFile("c:\pic.jpg")<br />
<br />
    End Sub

GeneralRe: File Stream Headache Pin
Anonymous16-May-04 11:11
Anonymous16-May-04 11:11 
GeneralRe: File Stream Headache - Permissions Problem ? Pin
BMS581917-May-04 3:34
BMS581917-May-04 3:34 
GeneralPjGrid.ocx - Dragging Tasks Pin
mac_hua14-May-04 3:30
mac_hua14-May-04 3:30 
GeneralSetup project for BHO Pin
Member 86274214-May-04 0:27
Member 86274214-May-04 0:27 
GeneralHelp....Datagrid and Ado question Pin
Anonymous13-May-04 23:38
Anonymous13-May-04 23:38 
GeneralHardware configuration Pin
pasho13-May-04 17:16
pasho13-May-04 17:16 
GeneralRe: Hardware configuration Pin
superwinsock13-May-04 22:31
superwinsock13-May-04 22:31 
GeneralRe: Hardware configuration Pin
Dave Kreskowiak14-May-04 8:11
mveDave Kreskowiak14-May-04 8:11 
GeneralRe: Hardware configuration Pin
pasho14-May-04 16:34
pasho14-May-04 16:34 
GeneralRe: Hardware configuration Pin
pasho14-May-04 16:38
pasho14-May-04 16:38 
GeneralMouse Wheel Scroll event in crystal report viewer Pin
Asif Rehman13-May-04 16:53
Asif Rehman13-May-04 16:53 
Generalstreamwriter problem Pin
Xun Ding13-May-04 9:50
Xun Ding13-May-04 9:50 
GeneralRe: streamwriter problem Pin
Daniel Turini13-May-04 10:22
Daniel Turini13-May-04 10:22 
GeneralRe: streamwriter problem Pin
Xun Ding13-May-04 10:48
Xun Ding13-May-04 10:48 
GeneralForms display Pin
Member 109674913-May-04 9:31
Member 109674913-May-04 9:31 
GeneralRe: Forms display Pin
Dave Kreskowiak13-May-04 11:50
mveDave Kreskowiak13-May-04 11:50 
QuestionImage problem??? Pin
Small Rat13-May-04 9:24
Small Rat13-May-04 9:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.