Hi, I have written code to connect to a database and retrieve binary data from it. I have four fields in my database and they are as follows:
DocID, Documents, blob, Authors, and DocType
The contents of DocType are "application/doc", "image/img" etc.
The following is my attempt to make the program set the mime type but I was stuck after retrieving the data from the database.
1For i = 0To ListBox1.Items.Count - 12If ListBox1.Items(i).SelectedThen34 DBCommand =New OdbcCommand("SELECT DocID, Document, DocTypes From ArchiveTB where Authors ='" & ListBox1.Items(i).Text & "'", DBConn)56 End If7 Next8 If Not IsNothing(DBConn) Then9 DBConn.Open()10 DBCommand.Connection = DBConn11 Dim DS As New DataSet12 Dim AD As New OdbcDataAdapter(DBCommand)1314'Do something15 'Do something16 'Do something1718 ListBox2.DataBind()1920 Dim buffer As Byte() = New Byte(contentLength - 1) {}2122 reader.GetBytes(0, 0, buffer, 0, contentLength)2324 Response.ContentType = "Put the content of DocType"2526 Response.BinaryWrite(buffer)2728End If How to I put the content of DocType in the line Response.ContentType = "Put the content of DocType" Thank you in advance for your help
try:
Response.ContentType = DirectCast(reader("DocType"), String)
you can also check here for the various content types
http://msdn2.microsoft.com/en-us/library/ms525208.aspx
Hi, thanks for responding. In your response what isreader and how is it related toString?I've read in the MSDN that the first argument of DirectCast has to be an expression and there has to be an inheritance or implementation relationship between it and the second argument.
reader was the variable name i took from your code sample.
I assumed that your were using a DataReader to pull your data from the database. The datareader would contain the columns/rows from your query and you would be able to access the string column of the readers current row containing the ContentType value as i indicated.
Are you not using a DataReader?
I see now that you have a listbox in your page (listbox2)
I should tell you that in order to output something other than text/html (as this is your case), your page must be totally empty! (I'm talking about the .aspx file, not the aspx.vb one)
@.mbanavige: would you be so kind as to check your private messages? thank you in advance![]()
Hi, thanks for responding and yes I'am now using a DataReader. However something has been worrying me, let me explain what I wanted to do. What I wanted to do is to put the mime types that are stored in the database and put them in the Response.ContentType=" mime type" , and you have shown me how to do that using DirectCast. But since I'm allowing users to choose multiple list items in my list box I might get more than one result for DocType. Even if I allow them to select just one list item I would still get more than one result for DocType. So how would the DataReader know which DocType to put in Response.ContentType if I more than one result for DocType is read by the DataReader?
Is that so? Hm. The values that you put in the dropdownlist must correspond to something UNIQUE in order for you to achive that. Either do that, or possibly add another dropdownlist. Both of these dropdownlist values should be unique (supposed you do a query like SELECT foo FROM table1 WHERE a=dropwdown1.Value AND b=dropdown2.Value )
Hi,
Do not bind the data directly to any of the control insted have the data in dataSet and read the data content into a Byte array and then write it as a Binary format so that you can get it
regards.
0 comments:
Post a Comment