用asp.net和c#编写的excel数据库网站 [英] website with excel database prepared in asp.net and c#

查看:70
本文介绍了用asp.net和c#编写的excel数据库网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人在网站的c#中有excel数据库连接的代码,那么请帮助我..

If anyone have code for excel database connectivity in c# in website then pls help me..

推荐答案

下面是一个工作代码



Given below is a working code

If fileExtension = ".xls" Then
     ExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fileName & ";Extended Properties='Excel 8.0;HDR=YES;'"
 Else
     ExcelConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & fileName & ";Extended Properties='Excel 12.0 Xml;HDR=YES;'"
 End If


 Dim dtFill As New DataTable

 Using oleDBConn As New OleDbConnection(ExcelConn)
     Dim daFill As New OleDbDataAdapter("Select * from [Attendance


,ExcelConn中选择*
daFill.Fill( dtFill)
结束使用
", ExcelConn) daFill.Fill(dtFill) End Using


使用OLEDB连接。

Make use of OLEDB connection.
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";





或plz查看贝尔沃代码





or plz check the belwo code

public static DataTable ReadExcel(string path)
{
    //create a DataTable to hold the query results
    DataTable dTable = new DataTable();

    try
    {
        if (!File.Exists(path))
            return null;

        //create the "database" connection string 
        string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

        //create the database query
        string query = "SELECT * FROM [Sheet1


这篇关于用asp.net和c#编写的excel数据库网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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