简体   繁体   中英

VB.net SQL Server Upload PDF

I am looking to upload a PDF from my VB.Net program to SQL Server. I have the below code.

the file I need to upload needs to go into the uDoc column and the file path (C:\\example.pdf) is the string inDoc.

any ideas on how to complete my code.

Thanks Rob

Sub UploadInvoice()
    Dim myConn As SqlConnection
    Dim inAcc As String
    Dim inType As String
    Dim inDoc As String


    inAcc = Form1.tb1Account.Text
    inType = frmInv.cbType.Text
    inDoc = frmInv.tbFile.Text



    myConn = New SqlConnection(strConnection)
    myConn.Open()

    Dim mycmd As New SqlCommand

    mycmd.CommandText = "INSERT INTO tblInvoice (UDate, AccNo, Type, UDoc) VALUES(GETDATE(),'" & inAcc & "','" & inType & "','" & inDoc & "')"




    mycmd.Connection = myConn
    mycmd.ExecuteNonQuery()

    myConn.Close()
End Sub

If this is an ASP.Net application, use the FileUpload control. It emits a file input field in the browser so you can select a file (or multiple if using .Net 4.5 and an HTML5 compliant browser). You won't be able to get the full file path, but that is generally irrelevant since a web application has no ability to read a client file system. Save the uploaded file to a location and store that location in the db.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM