Connect excel data from C#.net using OLEDBCONNECTION

Shah Samiur Rashid 0 Reputation points
2023-06-02T12:57:08.9033333+00:00

I want to connect an Excel file from c# using MS C#.net platform. Exploring web contents, I tried to connect using System.Data.OleDb. In namespace there is no error. But when I tried to establish a connection using System.Data.OleDb.OleDbConnection MyConnection; I got error.

So, I am stuck. Please help me.

Thanks.

Microsoft 365 and Office Excel For business Windows
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Shah Samiur Rashid 0 Reputation points
    2023-06-02T16:31:04.6566667+00:00

    Thanks a lot Karen. Please find your answer as follows-

    • Where is the Excel file?
      • "C:\Users\bups2\myData.xlsx"
    • Is the Excel file .xls or .xlsx ?
      • .xlsx
    • Please provide the connection string
      • I have used in the namespace - System.Data.Oledb
      • System.Data.OleDb.OleDbConnection MyConnection- When I declared the connection OleDbConnection gives error
    • What is the full error message text ?
      • The type name 'OleDbConnection' could not be found in the namespace 'System.Data.OleDb'. This type has been forwarded to assembly 'System.Data.OleDb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.
    • What do you mean by Exploring web contents ?
      • I mean that I explored internet to know how can I connect excel file from C#.net.

    Please help me. Thanks again.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.