Solved

returning data to webpage

Posted on 2011-09-26
2
248 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
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

777 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