读书人

问大家一个有关问题:在Excel中有一个单

发布时间: 2011-12-12 22:59:56 作者: rapoo

问大家一个问题:在Excel中有一个单元格是日期数据,我输入的明明是2006-7-15(打开excel也能看到它),但使用Ms OldDB读取的是2002-8-14,怎么
public partial class test_test : System.Web.UI.Page
{
OleDbConnection connOleDb;
protected void Page_Load(object sender, EventArgs e)
{
DataTable tblData = new DataTable();
DataSet ds = new DataSet();
string lFilePath = "E:/Projects/Caesar/a.xls ";
string connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+lFilePath+ ";Extended Properties= 'Excel 8.0;HDR=Yes;IMEX=1 ' ";

try
{
// Open the connection to the Excel document, and select the data from the first worksheet
connOleDb = new OleDbConnection(connectionstring);
connOleDb.Open();
OleDbDataAdapter da = new OleDbDataAdapter(@ "SELECT * FROM [a, Payroll Report$] ", connOleDb);
da.Fill(ds, "TableDate ");
tblData = ds.Tables[ "TableDate "];
DateTime dt = DateTime.Now;
city_hours.DataSource = tblData;
city_hours.DataBind();
}
catch (Exception ex)
{
string c_errorMessage = ex.Message + " <br /> <br /> ";
}
finally
{
connOleDb.Close();
}
}
}


<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "test.aspx.cs " Inherits= "test_test " %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">



<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> Untitled Page </title>
<script src= "../Ajax_Scripts/AjaxCore.js "> </script>
</head>
<body>
<form>

<asp:DataGrid CellPadding= "2 " ShowFooter=true BorderWidth= "1 " CellSpacing=0 BorderStyle=Groove id= "city_hours " Width= "100% " HorizontalAlign=center ShowHeader= "true " runat= "server ">
<HeaderStyle CssClass= "tableData " Font-Bold=true BackColor= "#ccccff " />
<ItemStyle CssClass= "tableData " BackColor= "ghostwhite " />
<AlternatingItemStyle CssClass= "tableData " BackColor=lightgray />
<FooterStyle CssClass= "tableData " Font-Bold=true BackColor= "#ccccff " />
</asp:DataGrid>

</form>

</body>
</html>

[解决办法]
每次都会变化?

读书人网 >asp.net

热点推荐