有一个Excel数据源,我正在查询并在数据网格中发布数据。诀窍是我想要一个字符串变量中的数据,但没有做到这一点。我曾尝试arrayLists和数组,我还没有达到那里,因为数据集有多个数据类型(数字,字符串)。需要将数据集转换为C#中的字符串
请帮帮我。源代码:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
string strConn;
string str="08/PST";
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=|DataDirectory|marks.xls;" +
"Extended Properties=Excel 8.0;";
//You must use the $ after the object you reference in the spreadsheet
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT [Subject ID] FROM [Employees$] where emp_id='" + str + "'", strConn);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet, "ExcelInfo");
DataGrid1.DataSource = myDataSet.Tables["ExcelInfo"].DefaultView;
DataGrid1.DataBind();
}
</script>
<html>
<head><title>Data Exported</title></head>
<body style="FONT-FAMILY: arial">
<h2>Simple Data Report
</h2>
<hr size="1" />
<form id="Form1" runat="server">
<asp:datagrid id="DataGrid1" runat="server" EnableViewState="False" ForeColor="Black" BackColor="White" CellPadding="3" GridLines="None" CellSpacing="1">
<HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C"></HeaderStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
</asp:datagrid>
</form>
</body>
</html>
在此先感谢
为清晰起见进行了编辑 – 2009-09-21 17:31:12
究竟是什么意思,您是否想要字符串变量中的所有数据?你还想将excel数据源导入原始字符串?我只是需要澄清,因为我无法想象你在问什么。 – 2009-09-21 17:31:33
请提供一些更多细节。 “诀窍是我想要一个字符串变量中的数据” - 不够清楚。你想要什么数据?你是绑定数据集表,它可以。什么字符串和你想要从哪里? – 2009-09-21 17:34:17