Solved

returning data to webpage

Posted on 2011-09-26
2
250 Views
Last Modified: 2012-05-12
I need to know how to take the following code in my aspx.cs page
 // Read file out of the database and returns it to client
        private void ShowTheFile(int FileID)
        {
            // Define SQL select statement
            string SQL = "SELECT FileSize, FileData, ContentType, Notes FROM FSUdata"
                       

            // Create Connection object
            OleDbConnection dbConn = new OleDbConnection(GetConnectionString());

            // Create Command Object
            OleDbCommand dbComm = new OleDbCommand(SQL, dbConn);

            // Open Connection
            dbConn.Open();

            // Execute command and receive DataReader
            OleDbDataReader dbRead = dbComm.ExecuteReader();

            // Read row
            dbRead.Read();

            // Clear Response buffer
            Response.Clear();

            // Set ContentType to the ContentType of our file
            Response.ContentType = (string)dbRead["ContentType"];

            // Write data out of database into Output Stream
            Response.OutputStream.Write((byte[])dbRead["FileData"], 0, (int)dbRead["FileSize"]);

            // Close database connection
            dbConn.Close();

            // End the page
            Response.End();
        }

Open in new window

And have the result show up on the results page as a table
 <form id="Form1" method="post" runat="server" enctype="multipart/form-data">
    <asp:Label ID="lab1" runat="server" Font-Bold="True">Please Select the Data File you will be uploading:</asp:Label>
    <br />
    <input id="filMyFile" type="file" runat="server">
    <p>
    </p>
    <asp:Label ID="notesLabel" runat="server" Font-Bold="True">Please give a description of the file you are uploading:<br /></asp:Label>
    <input id="lblnotes1" type="Text" runat="server">
    <br />
    <br />
  
    <asp:Button ID="cmdSend" runat="server" Text="Submit File to Database Folders" />
    <p>
    </p>
    <asp:Label ID="lblInfo" runat="server" Font-Bold="True" Visible="false"></asp:Label>
    <p>
    </p>
    <asp:Label ID="lblText1" runat="server" Font-Bold="True" Visible="True">This file will be placed in the FSU folder on the CEDB server.</asp:Label>
    <br />
    <br />
    <asp:Label ID="lblText2" runat="server" Font-Bold="True" Visible="True">This file and all of its meta data will be stored in uploadedData database</asp:Label>
    <asp:Image ID="imgFile" runat="server" Visible="False"></asp:Image> <br />
    <asp:Image ID="imgDB" runat="server" Visible="False"></asp:Image> <br />
    </form>
    </div>

Open in new window

0
Comment
Question by:Tagom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
dexterrajesh earned 500 total points
ID: 36708825
hi,

get the data from the reader like,

// Read row
while(dbRead.Read())
{
//below is just a sample on how to get the data from the reader object
string FileSize = dbRead[0].ToString();
string FileData = dbRead[1].ToString();
string ContentType = dbRead[2].ToString();
string Notes  = dbRead[3].ToString();
}
//

Open in new window

0
 

Author Comment

by:Tagom
ID: 36712419
That does not really help me a whole lot....kinda stumbling around with this:
Here is what I have in the file which does read back a table in the database - I was hoping to convert this code to what I have already done:
This is the hidden code used to fill the table:
 Dim objadapter As New OleDbDataAdapter(strSQL, objconnection)
        objadapter.Fill(objdataset, "rainevents")
        Dim objdataview As New DataView(objdataset.Tables("rainevents"))
        nwdat.DataSource = objdataview
        nwdat.databind()

Open in new window


This is the code used in the htm part:
<asp:datagrid id="nwdat" runat = "server"/>

What I need help with is taking the code from the aspx page listed in the original post and making it function the same as the code listed in the post...please
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question