animated405
asked on
DataSet to ArrayList?
Hello, new to .Net. I'm trying to present feedback to a user through data they will upload in an excel spreedsheet. I can get the file just fine onto a machine and display it through a datagrid. What I would really like to do is through it into memory, present it back to the user with different row styles depending on the information in the row (for errors) and also return an imagebutton with each row allow for the row to be editred in memory prior to ultimately being saved to the database.
Question is this: What is the best way to put the information from the excel sheet into memory, so that it can be spit back with dynamic style application and an additional WebControl?
I'm thinking I could use an ArrayList (becuase it's fast to update and flexible in size) but I don't know how to get all that into the arraylist and back into another DataList Control.
Here is what I have so far, thanks in advance!!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls
using System.IO;
namespace Com.Presentation
{
/// <summary>
/// Summary description for Upload.
/// </summary>
public class Upload : Com.Presentation.Component
{
protected System.Web.UI.WebControls.
protected System.Web.UI.HtmlControls
protected System.Web.UI.WebControls.
protected System.Web.UI.WebControls.
string sFileDir = "C:\\";
long lMaxFileSize = 100000;
private void Page_Load(object sender, System.EventArgs e)
{
}
private void DeleteFile(string sFileName)
{
/* Delete file , if it exists and I've put it on the server */
if (sFileName.Trim().Length > 0)
{
FileInfo fi = new FileInfo(sFileName);
if (fi.Exists)
{
fi.Delete();
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.cmdUpload.Click += new System.EventHandler(this.c
this.Load += new System.EventHandler(this.P
}
#endregion
private void cmdUpload_Click(object sender, System.EventArgs e)
{
if ((File1.PostedFile != null) && (File1.PostedFile.ContentL
{
/* get file name */
string sFileName = System.IO.Path.GetFileName
try
{
/* file can't be more than the declared size at begining of page */
if (File1.PostedFile.ContentL
{
/* save it */
File1.PostedFile.SaveAs(sF
lblMessage.Visible = true;
lblMessage.Text= "got " + sFileDir + sFileName + " loaded ok";
string strConn = "Provider=Microsoft.Jet.OL
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
DataSet myDataSet = new DataSet();
myCommand.TableMappings.Ad
myCommand.Fill(myDataSet);
DataGrid1.DataSource = myDataSet.Tables[0].Defaul
DataGrid1.DataBind();
}
else
{
/* file too big, reject it */
lblMessage.Visible = true;
lblMessage.Text = "file size over " + lMaxFileSize;
}
}
catch(Exception)
{
lblMessage.Visible = true;
lblMessage.Text = "some kind of error";
DeleteFile(sFileDir + sFileName);
}
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the replies. I'm still kind of confused, but your comments are helping me look more in the right direction. I'm keeping this open as I'm sure I have more comments soon.