none
RTF如何存入資料庫中阿 RRS feed

解答

所有回覆

  • rtf 是文字檔,所以開 String 欄位即可,也可以開 Byte()

     

    2008年8月23日 上午 09:11
  • :::參考看看將檔案直接存入資料庫裡及從資料庫裡讀取檔案

        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            '存入Excel檔
            Dim file As New System.IO.FileInfo("c:\test1.xls")
            Dim by(file.Length) As Byte
            file.OpenRead().Read(by, 0, file.Length)

            Dim cn As New SqlConnection("server=db-machine;database=sqltest;user id=sa;password=sa")
            Dim cmd As New SqlCommand("insert into test11 (n) values (@doc)", cn)
            Dim p As New SqlParameter("@doc", SqlDbType.Image)
            p.Value = by

            cmd.Parameters.Add(p)
            cn.Open()
            cmd.ExecuteNonQuery()
            cn.Close()

            MessageBox.Show("Finish")
        End Sub

        Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
            '讀取Excel檔
            Dim cn As New SqlConnection("server=db-machine;database=sqltest;user id=sa;password=sa")
            Dim cmd As New SqlCommand("Select n from test11 where id=1", cn)

            cn.Open()
            Dim dr As SqlDataReader = cmd.ExecuteReader

            dr.Read()

            Dim by() As Byte = dr("n")
            Dim ms As New System.IO.MemoryStream(by)
            Dim sr As New System.IO.BinaryReader(ms)

            Dim fs As New System.IO.FileStream("c:\test2.xls", IO.FileMode.Create)
            Dim sw As New System.IO.BinaryWriter(fs)

            Do While sr.PeekChar > -1
                sw.Write(sr.ReadByte)
            Loop

            sw.Close()
            fs.Close()
            sr.Close()
            ms.Close()

            MessageBox.Show("finish")

        End Sub

    2008年8月23日 下午 12:51
  • Dear 大大,

                   請問如果是在 Oracle DB  這一行要怎麼改變阿 Dim p As New SqlParameter("@doc", SqlDbType.Image)

    2008年8月25日 上午 01:35