Datetime with C#, ADO.NET and Excel

M

Mike Irwin

I'm trying to do a simple date-based SELECT using an Excel spreadsheet as
the data source. The spreadsheet contains a named range called
'showsRange', cell A1 in the spreadsheet is named 'Date' and the dates in
the column below it are entered as MM/DD/YYYY. What I want to do is to
select only the rows where the date is >= today's date. The spreadsheet is
bound to a DataGrid if that matters.

I'd appreciate any help with this as I'm a newbie to ADO.NET and C#. I
searched through the MSDN Library and Google but couldn't come up with any
information that could get me started in the right direction.

Here's a bit of what I have so far:

OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM showsRange",
objConn);



OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

objAdapter1.SelectCommand = objCmdSelect;

DataSet objDataset1 = new DataSet();

objAdapter1.Fill(objDataset1, "XLData");

showsGrid.DataSource = objDataset1.Tables[0].DefaultView;

showsGrid.DataBind();
 
W

William Ryan

So what was the problem? I just saw your post and was wondering if the
dates in the NamedRange were all the same...if they are different, you'd
definitely need a restriction. I used to do a lot with Excel but haven't
had to use it in a while, and I'm just kind of curious about how you bound
it to a DataGrid b/c Excel programming was always fun.
Mike Irwin said:
Nevermind this as I've figured it out.


Mike Irwin said:
I'm trying to do a simple date-based SELECT using an Excel spreadsheet as
the data source. The spreadsheet contains a named range called
'showsRange', cell A1 in the spreadsheet is named 'Date' and the dates in
the column below it are entered as MM/DD/YYYY. What I want to do is to
select only the rows where the date is >= today's date. The spreadsheet is
bound to a DataGrid if that matters.

I'd appreciate any help with this as I'm a newbie to ADO.NET and C#. I
searched through the MSDN Library and Google but couldn't come up with any
information that could get me started in the right direction.

Here's a bit of what I have so far:

OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM showsRange",
objConn);



OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

objAdapter1.SelectCommand = objCmdSelect;

DataSet objDataset1 = new DataSet();

objAdapter1.Fill(objDataset1, "XLData");

showsGrid.DataSource = objDataset1.Tables[0].DefaultView;

showsGrid.DataBind();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top