Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Uploading documents to SQL with vb.net [modified]

Uploading documents to SQL with vb.net [modified]

Scheduled Pinned Locked Moved ASP.NET
helpcsharpdatabasevisual-studio
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AaronM_NZ
    wrote on last edited by
    #1

    Ok, I have been searching for a while on this, and just cant work it out. I have web form with a INPUT type='file' called fileToAdd, and a textbox called tbTitle, and a button called btnUp. The IDE is complaining about the line 'objStream.Read (bDocTemp, 0, iDocLength)', saying "'1-dimensional array of Byte' cannot be converted to '1-dimensional array of Char' because 'Byte' is not derived from 'Char'." Fair enough, but I just cant figure out how to get it as a byte, all the examples I have found on the net for uploading images are the same as below, but it just wont work! If I DIM bDocTemp as a CHAR, the error goes away, but it wont work at run time. Argghh! Any help will be appreciated please! Thanks

    Protected Sub btnUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUp.Click
            Dim iDocLength As Integer = fileToAdd.PostedFile.ContentLength
            Dim sExt As String = fileToAdd.PostedFile.FileName.ToString()
            sExt = sExt.Substring(sExt.IndexOf(".", 0), 4)
    
            Dim objConn As New SqlConnection("Data Source=XXXXX;Initial Catalog=XXXX;Persist Security Info=True;User ID=XXXXX;Password=XXXXX")
            objConn.Open()
    
            Dim objCmd As New SqlCommand("spUploadFile", objConn)
            objCmd.CommandType = Data.CommandType.StoredProcedure
    
            Dim pTitle As New SqlParameter
            pTitle = objCmd.Parameters.Add("@Title", Data.SqlDbType.VarChar, 200)
            pTitle.Direction = Data.ParameterDirection.Output
            pTitle.Value = tbTitle.Text
    
            Dim pType As New SqlParameter
            pTitle = objCmd.Parameters.Add("@Type", Data.SqlDbType.VarChar, 3)
            pType.Value = sExt.ToString
    
            Dim bDocTemp(iDocLength - 1) As Byte
    
            Dim objStream As StreamReader = New StreamReader(fileToAdd.PostedFile.InputStream)
            objStream.Read (bDocTemp, 0, iDocLength)      '<----Error here
    
            Dim pDocument As New SqlParameter
            pDocument = objCmd.Parameters.Add("@Document", Data.SqlDbType.Image)
            pDocument.Value = bDocTemp
    
            Dim pUser As New SqlParameter
            pUser = objCmd.Parameters.Add("@user", Data.SqlDbType.VarChar, 50)
            pUser.Value = Request.ServerVariables("AUTH_USER").ToString
    
            objCmd.ExecuteNonQuery()
            objConn.Close()
    
        End Sub
    

    -- modified at 1:26 Monday 16th July, 2007

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups