I have a table in a SQL Server database that contains a field(data type image) that contains a text file. I'm trying to retrieve this file and save it onto the hard drive. I'm using the code below, but get I get the error 'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.' at line 11. This code worked fine when I tested it on the pubs database and exporting the logo field out of pub_info. I'm not quite sure why this doesn't work for my database. Can anyone see where I'm going wrong?
1 Dim cn As ADODB.Connection
2 Dim rs As ADODB.Recordset
3 Dim mstream As ADODB.Stream
4 cn = New ADODB.Connection
5 cn.Open("Provider=SQLOLEDB;data Source=server;Initial Catalog=database;User Id='userid';Password='password'")
6 rs = New ADODB.Recordset
7 rs.Open("Select * from filesubmissions where bundleId = 'F0000014.bun'", cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
8 mstream = New ADODB.Stream
9 mstream.Type = ADODB.StreamTypeEnum.adTypeBinary
10 mstream.Open()
11 mstream.Write(rs.Fields("BLOB").Value)
12 mstream.SaveToFile("c:\export.txt", ADODB.SaveOptionsEnum.adSaveCreateOverWrite)
13 rs.Close()
14 cn.Close()
Thanks
May I suggest you start by using ado.net?
|||try this one...
Dim BlobQuery As String
Dim RG As New Random
Dim InvoiceCSVData As Byte()
Dim strFileName As String = "TestingCSV_" + TextBox1.Text + "_" + CStr(RG.Next(1, 100000)) + ".CSV"
BlobQuery = "select BLOB from YourTableName where Condition'"
myOraConnection.Open()
myOraCmd = New OracleCommand(BlobQuery, myOraConnection)
myDR = myOraCmd.ExecuteReader(CommandBehavior.SequentialAccess)
myDR.Read()
InvoiceCSVData = CType(myDR(0), Byte())
myDR.Close()
myOraConnection.Close()
Response.AddHeader("Content-disposition", _
"attachment; filename=" & strFileName)
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(InvoiceCSVData)
Response.End()
No comments:
Post a Comment