Solved

returning data to webpage

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now