Advertisement

07.20.2008 at 12:19PM PDT, ID: 23580388
[x]
Attachment Details

VB.Net equivalent from VB6 CLOB Upload Procedure

Asked by Bartman88 in Microsoft Visual Basic.Net, Oracle 10.x

Tags: Microsoft, Visual Studio, 2005, Wrting data to a LOB - VB.Net Equivalent

I am trying to convert from VB6 to VB.Net and I am having a problem converting an upload procedure I used to use for reading large files (>>32k - .pdf, .xls, .zip, etc.) into CLOB fields in Oracle 10g tables.  The script worked quite well in VB6 and Access97 and 2002 but I cannot get this to work.  The biggest problem I am having is with:

     chunksize = 32000
 
    'Re adjust the buffer size
     buffer = String$(chunksize, 32)

and

    'Open the file.
    Open st1 For Binary As #fnum

and most importantly

Get #fnum, , buffer

Any assistance would be greatly appreciated.  I have attached to complete code below.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
Public Sub Upload2()
 
'Code for uploading any file into database.
 
Dim buffer As String
Dim chunksize, remainder As Long
Dim amount_written As Long
 
Dim ORide As Boolean
 
N1 = PID
n2 = POID
 
ORide = False
 
'Screen.MousePointer = 11
 
'strFilter = ahtAddFilterItem(strFilter, "PDF Files (*.PDF)", "*.pdf")
strFilter = ahtAddFilterItem(strFilter, "Any Files (*.*)", "*.*")
strInputFileName = ahtCommonFileOpenSave( _
    Filter:=strFilter, OpenFile:=True, _
    DialogTitle:="Select file to upload...", _
    Flags:=ahtOFN_HIDEREADONLY)
                    
st1 = strInputFileName
 
'st2 = Left(strInputFileName, Len(strInputFileName) - Len(Dir(strInputFileName)))
st2 = Dir(strInputFileName)
 
If st1 <> "" Then
    x1 = MsgBox("Upload:  " & vbCrLf & vbCrLf & st2 & vbCrLf & vbCrLf & "into database?", vbYesNo, "File Upload")
Else
    x1 = vbNo
End If
 
If x1 <> vbYes Then
    ORide = False
    MsgBox "No information uploaded", vbExclamation, "File Upload Cancelled."
Else
 
    'Document2 = st2
    DTitle2 = st2
    Me.requery
    Refresh
    'Document2.Locked = False
 
    'Create the OraSession Object.
    Set OraSession = CreateObject("OracleInProcServer.XOraSession")
 
    'Create the OraDatabase Object by opening a connection to Oracle.
    Set OraDatabase = OraSession.OpenDatabase(OracleSite, "USERNAME/PASSWORD", 0&)
 
    'Create the OraDynaset Object
     Set OraDynaset = OraDatabase.CreateDynaset("select * from po_link where proj_id = " & N1 & " and po_id = " & n2, 0&)
 
    Set PartDesc = OraDynaset.Fields("Attachment_C").Value
   
     chunksize = 32000
 
    'Re adjust the buffer size
     buffer = String$(chunksize, 32)
 
    fnum = FreeFile
 
    'Open the file.
    Open st1 For Binary As #fnum
 
    'Open "partdesc.dat" For Binary As #fnum
 
    'set the offset and PollingAmount properties for piece wiseWrite operation
    PartDesc.Offset = 1
    PartDesc.PollingAmount = LOF(fnum)
     remainder = LOF(fnum)
 
     If (LOF(fnum) = 0) Then
            MsgBox "File size is zero. Make sure that existence of File and its path are correct"
            Exit Sub
     End If
 
    'Lock the row for write operation
    OraDynaset.Edit
 
    Get #fnum, , buffer
        
    'Do first write operation
    amount_written = PartDesc.Write(buffer, chunksize, ORALOB_FIRST_PIECE)
 
    While PartDesc.Status = ORALOB_NEED_DATA
        remainder = remainder - chunksize
        If remainder < chunksize Then
            piecetype = ORALOB_LAST_PIECE
            chunksize = remainder
        Else
            piecetype = ORALOB_NEXT_PIECE
        End If
        Get #fnum, , buffer
        amount_written = PartDesc.Write(buffer, chunksize, piecetype)
    
    Wend
 
    Close fnum
    
    'call Update method to commit the transaction
    OraDynaset.update
    OraDynaset.Close
        
    'Free LOB
    Set PartDesc = Nothing
    
    OraDatabase.Close
    Set OraSession = Nothing
 
    checkset
    
    MsgBox "File: " & vbCrLf & vbCrLf & st2 & vbCrLf & vbCrLf & " uploaded successfully.", vbInformation, "Upload Complete"
 
End If
 
'Screen.MousePointer = 0
 
End Sub
[+][-]07.20.2008 at 05:34PM PDT, ID: 22047546

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.20.2008 at 06:30PM PDT, ID: 22047640

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 06:43PM PDT, ID: 22047660

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 06:59PM PDT, ID: 22047691

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 11:59AM PDT, ID: 22072639

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 12:25PM PDT, ID: 22072901

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 01:44PM PDT, ID: 22073638

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 01:50PM PDT, ID: 22073694

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 04:33PM PDT, ID: 22074905

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 06:50PM PDT, ID: 22075566

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.05.2008 at 05:32PM PDT, ID: 22166295

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, Oracle 10.x
Tags: Microsoft, Visual Studio, 2005, Wrting data to a LOB - VB.Net Equivalent
Sign Up Now!
Solution Provided By: Bartman88
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628