oledb

Unknown problem while exporting excel to System.DataTable

社会主义新天地 提交于 2019-12-02 03:17:56
I am trying to get data from Excel File to DataTable. Here's my code-snippet : FilePath = WebConfig.SavePath + "Book2.xls"; // Create the connection object OleDbConnection oledbConn = new OleDbConnection(WebConfig.ExcelConnection(FilePath)); // Open connection oledbConn.Open(); // Create OleDbCommand object and select data from worksheet Sheet1 //WebConfig.SheetNameFirstExcel OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + "Sheet1" + "$]", oledbConn); // Create new OleDbDataAdapter OleDbDataAdapter oleda = new OleDbDataAdapter(); oleda.SelectCommand = cmd; // Create a DataSet which

How to retrieve actual OleDb table schema (excluding additional table columns)

点点圈 提交于 2019-12-02 03:07:44
When I run this code it is also retrieving some other fields which are not present in the table. How can I overcome this? Dim conn As New OleDb.OleDbConnection 'Create a connection string for an Access database Dim strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\check\a.mdb" 'Attach the connection string to the connection object conn.ConnectionString = strConnectionString 'Open the connection conn.Open() Dim Restrictions() As String = {Nothing, Nothing, selected, Nothing} Dim CollectionName As String = "Columns" Dim dt As DataTable = conn.GetSchema(CollectionName,

sqlbulkcopy from Excel via ACE.OLEDB truncates text to 255 chars

你说的曾经没有我的故事 提交于 2019-12-02 02:54:39
Pretty straight-forward import using SqlBulkCopy: string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\""; using (OleDbConnection excelConnection = new OleDbConnection(excelConnectionString)) { excelConnection.Open(); OleDbCommand cmd = new OleDbCommand("Select " + fileID.ToString() + " as [FileID], * from [Sheet1$] where [Text] IS NOT NULL", excelConnection); OleDbDataReader dReader = cmd.ExecuteReader(); using (SqlBulkCopy sqlBulk = new SqlBulkCopy(ConfigurationManager.ConnectionStrings[

How do I connect to SQL Server using OLEDB using Windows Authentication connection string

穿精又带淫゛_ 提交于 2019-12-02 02:07:39
问题 I have SQL Server 2010 running in windows auth mode and the proper groups have been assigned. I can connect via the SQL Server Client Studio using windows auth. That works. But when connecting using .NET OLEDB connections it fails and I can't figure out why. Here is the string: data source=172.20.0.113;initial catalog=ForgeEnterprise;Integrated Security=SSPI;multipleactiveresultsets=True;App=EntityFramework And here is the error: Login failed for user 'MOMENTUMI\jmcclure' Is there something I

db connection pool across processes

假装没事ソ 提交于 2019-12-02 02:02:46
We have a client/server application that consists of multiple EXEs. The data access layer is on the same physical tier as the client in a library shared by our EXE modules. ODBC and OleDB connection pools are managed per-process; are there techniques for sharing DB connections across processes (other than moving the data access layer to a middle tier)? Database connections in OLEDB and ODBC are intrinsically process bound. At the lowest levels, a sql server database connection is using an IPC mechanism like named pipes, shared memory, or tcp sockets. Other databases probably use network

How do I list all the queries in a MS Access file using OleDB in C#?

帅比萌擦擦* 提交于 2019-12-02 01:40:42
I have an Access 2003 file that contains 200 queries, and I want to print out their representation in SQL. I can use Design View to look at each query and cut and paste it to a file, but that's tedious. Also, I may have to do this again on other Access files, so I definitely want to write a program to do it. Where are queries stored an Access db? I can't find anything saying how to get at them. I'm unfamiliar with Access, so I'd appreciate any pointers. Thanks! Procedures are what you're looking for: OleDbConnection conn = new OleDbConnection(connectionString); conn.Open(); DataTable queries =

Error External table is not in the expected format

谁说胖子不能爱 提交于 2019-12-02 01:26:54
I am trying to get data to sqlserver2005 on my C# windows application, from sheet1.xls file through oledb connection in visual studio-2008 and I am using windows7 os and I didn't installed excel on my system. This is my connection string: string excelconnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +excelfilepath + ";"+"Extended Properties='Excel 8.0;HDR=Yes;'"; I tried many ways but still i am getting this error : "External table is not in the expected format. " Please help me. Use Microsoft.ACE.OLEDB.12.0 for excel files string excelconnectionstring = "Provider=Microsoft

Excel SQL Syntax JET OleDB Reference?

橙三吉。 提交于 2019-12-02 01:25:20
I´m querying an Excel Sheet from a .NET Application with an Jet driver. Are there any ressources on SQL on Excel files covering: Formats, DataTypes, DataConversions, Supported Statements ... ? Thank you The SQL syntax is the same as for the Access database engine (Jet, whatever) version 4.0 i.e. Access2000 through Access2003. The way the driver/provider works out data types is a little odd and can be frustrating that you can't just specify what they should be (as you can e.g. for a text file using a schema.ini file). This article I wrote on the subject many moons ago still gets a lot of

Syntax error in INSERT statement into MS Access

末鹿安然 提交于 2019-12-02 01:19:02
I couldn't find the syntax error in the following INSERT statement. public partial class doRegister : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\database"; using (OleDbConnection con = new OleDbConnection(str)) using (OleDbCommand cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO users (staffID,accessLevelIdD,username,password,email) VALUES (@staffID, '2', @username,@password,@email)"; cmd.Parameters.AddWithValue("@staffID", Request.Form["staffid"]); cmd.Parameters.AddWithValue("@password

In ADO.NET, are there restrictions where SQL parameters can be used in the SQL query?

﹥>﹥吖頭↗ 提交于 2019-12-02 01:11:35
This question is merely for educational purposes, as I'm not currently building any application that builds SQL queries with user input. That said, I know that in ADO.NET you can prevent SQL Injection by doing something like this: OleDbCommand command = new OleDbCommand("SELECT * FROM Table WHERE Account = @2", connection); command.Parameters.AddWithValue("@2", "ABC"); But assuming that your application is designed in such a way that the user can actually enter the name of the table, can you do the following? (I don't care if it's a bad idea to allow the users to supply the name of the table,