0

I have the following:

string oledbcmd = "";
        string constr =
            @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Excel.xls;@Extended Properties='Excel 8.0;HDR=Yes;";

            oledbcmd = "Select top (1) * From [CLIENTES$] ORDER BY id desc";

        OleDbCommand oconn = new OleDbCommand(oledbcmd, con);
        OleDbDataAdapter sda = new OleDbDataAdapter(oconn);

        DataTable data = new DataTable();
        sda.Fill(data);

It fails. What is wrong with that query? I want to get the last row that was inserted.

2
Contributors
2
Replies
18
Views
1 Year
Discussion Span
Last Post by riahc3
0

Guess you forgot to open your connection.

Votes + Comments
Should hae added that it works without the order by and top...
0

Sadly, I cannot edit but I want to make clear that

oledbcmd = "Select * From [CLIENTES$]";

Works. It isnt a connection issue or anything else (the connection code is already implemented but posting a huge chunk of code makes no sense when just one line is the culprit.

Edited by riahc3

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.