English 中文(简体)
5. 服务器从图像现场下载
原标题:SQL Server Open File From Image Field

我在2005年金库服务器中拥有一个包含文件,主要是pdf文件的图像。 当我在数据库中看到这个领域时,它就认为数据是作为星号储存的。 我已广泛走动,与万国邮联在一起。 以下的净功能是将外地转换成实际档案,但只产生一个文件,其中载列轴心,而不是外地应代表的档案。

这是田地数据样本(为了隐私的目的,我已经做了改动):

0x1F8B0800000000000400EDBD07601C499625262F6DCA7B7F4AF

我写到的职能是把外地改为一份文件:

    Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click

    sql = New MySqlClient.MySqlConnection(connectionString)

    Dim cmd As New MySqlClient.MySqlCommand("SELECT docdata FROM temp.temp_docs WHERE docid = " + TextEdit1.Text, sql)

    sql.Open()

    Dim dr As MySqlClient.MySqlDataReader = cmd.ExecuteReader()

    dr.Read()

    Dim b(dr.GetBytes(0, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte

    dr.GetBytes(0, 0, b, 0, b.Length)

    dr.Close()

    sql.Close()

    Dim DestFilePath As String = "C:... Desktop" & String.Format("{0:hhmmss}", DateTime.Now) & ".pdf"

    Dim fs As New System.IO.FileStream(DestFilePath, IO.FileMode.Create, IO.FileAccess.Write)

    fs.Write(b, 0, b.Length)

    fs.Close()

End Sub

谁会发现我错失的地方? 能否从服务器的查询中打开文件?

最佳回答

IMAGE fields do not contain hex strings . They contain binary data which you read it as a binary stream using SqlBytes.Stream. You copy the stream into your desired file using Stream.CopyTo.

问题回答

暂无回答




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签