Tag: oledbconnection

Oledb或ODBC创build没有安装Office的工作簿或工作表

我有一个2008R2服务器与SQL和IIS; 没有安装MS-Office套装,但是我需要根据用户请求发送dynamic创build的Excel回复。 安装“Microsoft Access数据库引擎2010可再发行组件”,根据规范,Excel驱动程序(等)应该到位。 试图用下面的连接string创build一个新的数据库: Using ExcelConnection As New System.Data.OleDb.OleDbConnection( "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Name + ";" + "Mode=ReadWrite;" + "ReadOnly=false;" + "Extended Properties=Excel 12.0;") ExcelConnection.Open() …. end Using 错误 [OleDbException (0x80004005): Could not find installable ISAM.] System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +318 System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +88 System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions […]

如何在Excel中读取下拉列表的值并添加到数据表C#

你好,我面临以下问题:我有一个Excel文件,有一些单元格下拉列表。 我正在尝试读取excel并将其添加到数据表单以便操作数据。 我已经设法读取excel并将其添加到数据库,但我的方法读取的所有与dropdownlist的单元格的值,它不只读取所选的一个。 例如,我给了一个单元格的三个值(1,2,3),单元格的值为1.我的方法读取excel,并将不同行中的所有值添加到数据表中。 所以它增加了1,2,3。 你可以看到我的代码如下: protected void ddlReviewStatus_SelectedIndexChanged(object sender, EventArgs e) { string date = DateTime.Now.ToShortDateString(); string finalDate = date.Replace("/", ""); string fileName = "test.xlsx"; DropDownList ddlReviewStatus = sender as DropDownList; GridViewRow row = (GridViewRow)ddlReviewStatus.NamingContainer; string companyName = ((Label)row.FindControl("lblCompName")).Text; string filePath = ReportTemplatesPath + "\\" + companyName + "\\" + finalDate + "\\" + […]

读取损坏的Excel使用C#

我想打开并使用C#控制台应用程序从损坏的Excel中读取数据。我试着用这个代码: public System.Data.DataTable EXc(string path, string savedFile) { try { Missing missing = Missing.Value; Excel.Application excel = new Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Open(path, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, Microsoft.Office.Interop.Excel.XlCorruptLoad.xlRepairFile); workbook.Close(true, missing, missing); if (workbook != null) { workbook.SaveAs(savedFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, missing, missing, missing, missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, missing, missing, missing, […]

MS Access的OLEDBConnection Excel问题

所以我已经search了大约2天了,虽然我可以find很多关于如何将Excel工作表放入GridView的例子,但是没有一个适用于我。 这是我的目标:我需要读取一个Excel文件,其中有一个工作表,它应该始终是一个工作表,在ASP.NET网站中的一个GridView和我使用VB.Net代码后面的文件。 我尝试了一种方法,试图使用表名的Schema(为了获得表名),但是不pipe表的名字是什么,它总是以“Algrip”的forms返回,其中任何一个工作簿中都没有这个名字的表我用一个testing。 所以我放弃了这一点,现在正在使用这个代码:(哪个工作完成,有点) 'Setup Variables Dim xlConnStr As String = "" Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName) Dim Extension As String = Path.GetExtension(FileUpload1.PostedFile.FileName) Dim FolderPath As String = ConfigurationManager.AppSettings("FolderPath") Dim sheetname As String = InputBox("Enter Sheetname: ", "Excel Worksheet name") 'Adjust Sheetname sheetname = sheetname + "$" 'Set Connection based on Excel File Extension […]

将excel表转换为C#DataTable裁剪掉一些数据

我正在使用下面的代码将工作表上的一组Excel数据转换为C#dataTable: var connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _filename + ";Extended Properties=\"Excel 12.0;HDR=YES\";"); var adapter = new OleDbDataAdapter("SELECT * FROM [owssvr$]", connection); connection.Open(); var ds = new DataSet(); adapter.Fill(ds); connection.Close(); return ds.Tables[0]; 这似乎工作正常,但是当我循环通过dataTable提取值,我有一个字段是约400个字符,当我从数据表中抓住它,我只看到第255个字符。 有什么办法,我可以从Excel导入这个字符限制?

From子句Excel中的语法错误

public void SetConnection(string text1, string text2, string text3, string text4, string text5, string text6, string text7) { connectionString1 = "Initial Catalog=testdb; Data Source=work\\sqlexpress"; database = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\Users\\test.xls';Extended Properties= \"Excel 8.0;HDR=Yes;IMEX=1\";"); database.Open(); database1 = new OleDbConnection("Provider=SQLOLEDB.1;" + connectionString1); database1.Open(); } data1 = DataAccess.DatabaseTables("SELECT * from [Sheet1$])", DataAccess.database); public DataTable DatabaseTables(string QueryString, OleDbConnection DataConnection) { OleDbCommand […]

用OleDB读取Excel文件以错误的格式返回UPC号码

我必须在Web应用程序中使用OleDB读取Excel文件,并将数据保存到数据库中。 访问文件并使用DataAdapter或OleDbDataReader读取它的作品。 我需要指定IMEX = 1和TypeGuessRows = 0,因为文件中的数据有我需要parsing的标题,但它们不在第一行。 所以基本上,我需要读取行,直到我打一个已知的标题,然后开始parsing所有的数据。 在第一列中有这样的值的UPC号码: 5053366261702但即使字段被读取为文本,OleDbDataReader以科学方式返回数字,如下所示: 5.05337E+12 如果我不以文本forms读取这些行,数字将被正确地返回,但标题将会消失。 我添加了代码的重要部分。 在此先感谢您的帮助。 string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + fileName + "';Extended Properties='Excel 12.0;HDR=No;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0'"; using (OleDbConnection objConn = new OleDbConnection(conn)) { objConn.Open(); var exceltables = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new Object[] { null, null, null, "TABLE" }); var tablename = exceltables.Rows[0]["TABLE_NAME"]; using (OleDbCommand objCmdSelect = new OleDbCommand("SELECT […]

使用C#与OleDbConnection获取特定工作表的Excel文件中的列名

到目前为止,我已经设法得到整个Excel文件的列名,但我想要做的是获得给定表(表)的Excel文件的列名。 我如何修改代码来实现这一点。 我一直在尝试一段时间没有积极的结果,任何帮助非常感激。 public static List<String> ReadSpecificTableColumns(string filePath, string sheetName) { var columnList = new List<string>(); try { var excelConnection = new OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + filePath + "';Extended Properties='Excel 12.0;IMEX=1'"); excelConnection.Open(); var columns = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, null); excelConnection.Close(); if (columns != null) { columnList.AddRange(from DataRow column in columns.Rows select column["Column_name"].ToString()); } } catch (Exception exception) { […]

Microsoft Office Access数据库引擎无法打开或写入文件“

数据需要从Excel工作表中读入.net gridview。 这里是aspx和aspx.cs代码。 ASPX: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Read and Display Data From an Excel File (.xsl or .xlsx) in ASP.NET</title> </head> <body> <form id="form1" runat="server"> <div> <b>Please Select Excel File: </b> <asp:FileUpload ID="fileuploadExcel" runat="server" />&nbsp;&nbsp; <asp:Button ID="btnImport" runat="server" Text="Import Data" OnClick="btnImport_Click" /> <br /> <asp:Label ID="lblMessage" […]

无法parsing一些excel列

美好的一天! 我尝试打开并parsingExcel文件到数据集。 所以,我使用OleDbConnection: if (_filePath.Substring(_filePath.LastIndexOf('.')).ToLower() == ".xlsx") // strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" // + _filePath + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\""; strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _filePath + ";Extended Properties=\"Excel 12.0 Xml;HDR=" + HDR + ";IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text;\""; // strConn="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _filePath + ";Extended Properties=Excel 12.0;"; else strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _filePath + […]