如何使用ASP.Net在访问中插入Excel文件数据 [英] how to insert a excel file data in access using ASP.Net

查看:86
本文介绍了如何使用ASP.Net在访问中插入Excel文件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ASP.Net

解决方案

在访问中插入Excel文件数据您可以使用OleDbConnection $ b $读取数据b 
< pre lang = c# > OleDbConnection oconn = null;
string FilePath =C:\\dotnetmentors\\Products.xlsx;
oconn = new OleDbConnection(@Provider = Microsoft.ACE.OLEDB.12.0;
Data Source =+ FilePath +;
Extended Properties = Excel 8.0);

DataTable dtCategories = new DataTable();
oconn.Open();
dtCategories = oconn.GetOleDbSchemaTable(
OleDbSchemaGuid.Tables,null);
oconn.Close();

列表< ListItem > lstCategories = new List < ListItem > ();

string sheetName = string.Empty;
foreach(dtCategories.Rows中的DataRow dr)
{
sheetName = dr [TABLE_NAME]。ToString();
if(!sheetName.Contains(Sheet))
lstCategories.Add(new ListItem(
sheetName.Replace(


, )));
} < / pre >





了解更多信息并一步一步



< a href =http://dotnetmentors.com/aspnet/display-excel-data-in-web-page.aspx> http://dotnetmentors.com/aspnet/display-excel-data-in-web-page .aspx [ ^


how to insert a excel file data in access using ASP.Net

解决方案

you can read data using OleDbConnection

<pre lang="c#">OleDbConnection oconn = null;
            string FilePath = "C:\\dotnetmentors\\Products.xlsx";
            oconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;
                    Data Source=" + FilePath + ";
                            Extended Properties=Excel 8.0");

            DataTable dtCategories = new DataTable();
            oconn.Open();
            dtCategories = oconn.GetOleDbSchemaTable(
                        OleDbSchemaGuid.Tables, null);
            oconn.Close();

            List<ListItem> lstCategories = new List<ListItem>();

            string sheetName = string.Empty;
            foreach (DataRow dr in dtCategories.Rows)
            {
                sheetName = dr["TABLE_NAME"].ToString();
                if (!sheetName.Contains("Sheet"))
                    lstCategories.Add(new ListItem(
                                sheetName.Replace("


", ""))); }</pre>



for more info and step by step

http://dotnetmentors.com/aspnet/display-excel-data-in-web-page.aspx[^]


这篇关于如何使用ASP.Net在访问中插入Excel文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆