C# 获取xlsx表名
来源:互联网 发布:淘宝学院官网 编辑:程序博客网 时间:2024/06/03 00:23
protected void Button1_Click(object sender, EventArgs e)
{
string strConnection1 = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=";
string strPath = Server.MapPath("file") + "\\" + FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("file") + "\\" + FileUpload1.FileName);
OleDbConnection con = new OleDbConnection(strConnection1+strPath);
Response.Write(strConnection1);
con.Open();
try
{
DataTable schema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
//下面取得第一个表名
string strTableName = schema.Rows[0]["TABLE_NAME"].ToString();
Response.Write(strTableName);
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + strTableName + "]", con);
DataSet ds = new DataSet();
da.Fill(ds);
da.Dispose();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
{
string strConnection1 = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=";
string strPath = Server.MapPath("file") + "\\" + FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("file") + "\\" + FileUpload1.FileName);
OleDbConnection con = new OleDbConnection(strConnection1+strPath);
Response.Write(strConnection1);
con.Open();
try
{
DataTable schema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
//下面取得第一个表名
string strTableName = schema.Rows[0]["TABLE_NAME"].ToString();
Response.Write(strTableName);
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + strTableName + "]", con);
DataSet ds = new DataSet();
da.Fill(ds);
da.Dispose();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
- C# 获取xlsx表名
- C#获取所有表名
- C#获取EXCEL所有表名
- C#获取EXCEL所有表名
- C# 获取属性名
- C#获取方法名
- c# 获取变量名
- C#获取打印机名
- C# access 获取所有表名和字段名
- C#获取SQLServer数据库表名和字段名
- C#获得Access数据库中的表名,以及根据表名获取字段名
- c# 获取access所有表名 获取指定表所有字段名
- c# 获取access所有表名 获取指定表所有字段名
- C#通过OleDb查询获取Access数据库表名
- C#中获取Excel文件的表名
- C# 获取Access数据库中所有的表名
- C# :excel读取表名,这样获取的表名不会出错
- 在C#中获取Access数据库中的所有表名和列名
- 快速学习JavaScript面向对象编程
- Python - for()循环 详解 及 代码
- Java 正确的做字符串编码转换
- 使用C编译器编写shellcode
- C++基础学习笔记----第十三课(操作符重载-下)
- C# 获取xlsx表名
- paint和paintComponent方法的关系
- Android读写文件
- 火星文 wa
- thinkphp验证码更改
- [LeetCode]Path Sum,解题报告
- CF 370
- eclipse在线安装SVN出错
- No bean named 'userService' is defined 问题解决 maven ssh