Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How can I access excel from VB2008 Express.net

WildScotWildScot Member Posts: 4
I have tried but having difficulty with understanding MDAC error.
Anybody help please?
Thanks

Comments

  • s_sreenaths_sreenath Member Posts: 20
    : I have tried but having difficulty with understanding MDAC error.
    : Anybody help please?
    : Thanks
    :
    which connection you have used? Can you more details.

    But, as for as i know you can use OLEDB connection for accessing the, excel sheet from .net applications.

    If you need the code I will post it over here.
  • WildScotWildScot Member Posts: 4
    : : I have tried but having difficulty with understanding MDAC error.
    : : Anybody help please?
    : : Thanks
    : :
    : which connection you have used? Can you more details.
    :
    : But, as for as i know you can use OLEDB connection for accessing
    : the, excel sheet from .net applications.
    :
    : If you need the code I will post it over here.
    :


    Thanks for the reply.
    The error message of 'The .Net Framework Data Providers require Microsoft Data Access Components(MDAC). Please install Microsoft Data Access Components(MDAC) version 2.6 or later' comes from VB Help for downloading from Excel to dataset. Where can I check whether I have got it?

    It sounds as though your offer to send me the code would be very useful.
    Thanks

  • s_sreenaths_sreenath Member Posts: 20
    : : : I have tried but having difficulty with understanding MDAC error.
    : : : Anybody help please?
    : : : Thanks
    : : :
    : : which connection you have used? Can you more details.
    : :
    : : But, as for as i know you can use OLEDB connection for accessing
    : : the, excel sheet from .net applications.
    : :
    : : If you need the code I will post it over here.
    : :
    :
    :
    : Thanks for the reply.
    : The error message of 'The .Net Framework Data Providers require
    : Microsoft Data Access Components(MDAC). Please install Microsoft
    : Data Access Components(MDAC) version 2.6 or later' comes from VB
    : Help for downloading from Excel to dataset. Where can I check
    : whether I have got it?
    :
    : It sounds as though your offer to send me the code would be very
    : useful.
    : Thanks
    :
    :
    I think you are using some wizard for connecting it with the Excel sheet to dataset. But I have done it programatically. Here is the Code for getting the Excel sheet data into DataSet.

    public string GetOledbConnectionString(string fileName)
    {
    return "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + fileName + ";" + "Extended Properties='Excel 8.0;HDR=YES;'";

    }
    //give ur call this function and pass the filename with fullpath
    public void RawUploadDumpEntries(string fileName)
    {
    string stroledbConnectionString = helperObject.GetOledbConnectionString(fileName);
    try
    {
    OleDbConnection oledbRevenueImportConnection = new OleDbConnection(stroledbConnectionString);
    string strCommand ="select * from [sheetName$]";
    OleDbCommand oledbImportCommand = new OleDbCommand(strCommand, oledbRevenueImportConnection);
    oledbRevenueImportConnection.Open();
    OleDbDataAdapter oledbAdapter = new OleDbDataAdapter(oledbRevenueImportCommand);
    DataSet ds = new DataSet();
    oledbAdapter.Fill(ds);
    oledbImportConnection.Close();
    }
    catch (OleDbException oledbException)
    {
    throw new Exception("Put your error messaged here", oledbException);
    }
    }

    If u still face some problem. Post here I will let you know, what can be done.


  • WildScotWildScot Member Posts: 4
    Appologies for not replying sooner but this is the first time I have used a forum and my replies got lost - operator error!!
    Many thanks for your reply. Unfortunately it is in 'C'(?) which I don't know so I am having difficulty in transposing it.
    This was my first attempt:

    Public Sub ReadIntoDataSet()
    Dim cn As OleDbConnection
    Dim cmd As OleDbDataAdapter
    Dim dataset1 As New DataSet()

    cn = New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" & _
    "data source=d:WeatherData8Weather 2008_12.xls;Extended Properties=Excel 8.0")
    cmd = New OleDbDataAdapter("select * from [AnnualData$]", cn)

    cn.Open()
    cmd.Fill(dataset1)
    cn.Close()
    End Sub

    The program stalls at the line cn.Open() and gives the MDAC error message.
    Do you think you could amend my code or suggest a way to stop the MDAC error message?
    Thanks
  • s_sreenaths_sreenath Member Posts: 20
    The problem in you code is nothing much big. For a adapter like SqlDataAdapter or oledb adapter you no need to open the connection mannualy, i mean the statement "[b]cn.open()[/b]", is not necessary at all. Since the adapter will take care of all those things. "cn.close()" is also not necessary as far as i know. But you can still specify, if you get MDAC error at that place.
    "Always Smile :)"
Sign In or Register to comment.