Click here to Skip to main content
15,884,099 members
Home / Discussions / C#
   

C#

 
GeneralRe: to access latitudes and longitudes from database Pin
Ennis Ray Lynch, Jr.31-Dec-12 5:36
Ennis Ray Lynch, Jr.31-Dec-12 5:36 
GeneralRe: to access latitudes and longitudes from database Pin
PIEBALDconsult31-Dec-12 6:22
mvePIEBALDconsult31-Dec-12 6:22 
Questionhow to extract tag in regular expressions c# Pin
ngoanrazor30-Dec-12 5:02
ngoanrazor30-Dec-12 5:02 
AnswerRe: how to extract tag in regular expressions c# Pin
PIEBALDconsult30-Dec-12 5:39
mvePIEBALDconsult30-Dec-12 5:39 
GeneralRe: how to extract tag in regular expressions c# Pin
OriginalGriff30-Dec-12 21:20
mveOriginalGriff30-Dec-12 21:20 
GeneralRe: how to extract tag in regular expressions c# Pin
Brisingr Aerowing31-Dec-12 12:16
professionalBrisingr Aerowing31-Dec-12 12:16 
GeneralRe: how to extract tag in regular expressions c# Pin
PIEBALDconsult31-Dec-12 12:24
mvePIEBALDconsult31-Dec-12 12:24 
QuestionBoolean function to return true/false Pin
Member 970415330-Dec-12 2:57
Member 970415330-Dec-12 2:57 
I have the following function which I got online, and have changed to suit my needs :-

private Boolean SheetExists(string strFilename)
{
    Boolean Match = false;
    OleDbConnection objConn = null;
    System.Data.DataTable dt = null;
    try
    {
        String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
            "Data Source=" + strFilename + ";Extended Properties=Excel 8.0;";
        objConn = new OleDbConnection(connString);
        objConn.Open();
        dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        String[] excelSheets = new String[dt.Rows.Count];
        int i = 0;
        foreach (DataRow row in dt.Rows)
        {
            excelSheets[i] = row["TABLE_NAME"].ToString();
            i++;
        }
        for (int j = 0; j < excelSheets.Length; j++)
        {
            if (excelSheets[j] == "Sheet1$")
            {
                Match = true;
            }
        }
        if (Match == true)
            return true;
        else
            return false;
    }
    finally
    {
        if (objConn != null)
        {
            objConn.Close();
            objConn.Dispose();
        }
        if (dt != null)
        {
            dt.Dispose();
        }
    }
}


Basically it checks if sheet1 exists in a workbook. I'm currently using the variable "Match" to obtain a "return true" or a "return false". I'm sure it possible to modify the code so that it returns the true/false directly, I just can't figure out how.
Any ideas? Thanks
AnswerRe: Boolean function to return true/false Pin
Richard MacCutchan30-Dec-12 4:12
mveRichard MacCutchan30-Dec-12 4:12 
GeneralRe: Boolean function to return true/false Pin
Member 970415330-Dec-12 4:18
Member 970415330-Dec-12 4:18 
GeneralRe: Boolean function to return true/false Pin
Richard MacCutchan30-Dec-12 4:25
mveRichard MacCutchan30-Dec-12 4:25 
GeneralRe: Boolean function to return true/false Pin
Member 970415330-Dec-12 5:42
Member 970415330-Dec-12 5:42 
GeneralRe: Boolean function to return true/false Pin
Richard MacCutchan30-Dec-12 5:45
mveRichard MacCutchan30-Dec-12 5:45 
AnswerRe: Boolean function to return true/false Pin
Matt T Heffron3-Jan-13 19:54
professionalMatt T Heffron3-Jan-13 19:54 
GeneralRe: Boolean function to return true/false Pin
Member 97041533-Jan-13 21:00
Member 97041533-Jan-13 21:00 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 9:55
Member 97041537-Jan-13 9:55 
AnswerRe: Boolean function to return true/false Pin
Matt T Heffron7-Jan-13 10:17
professionalMatt T Heffron7-Jan-13 10:17 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 10:26
Member 97041537-Jan-13 10:26 
AnswerRe: Boolean function to return true/false Pin
Matt T Heffron7-Jan-13 11:01
professionalMatt T Heffron7-Jan-13 11:01 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 11:30
Member 97041537-Jan-13 11:30 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 11:57
Member 97041537-Jan-13 11:57 
AnswerRe: Boolean function to return true/false Pin
Matt T Heffron7-Jan-13 12:03
professionalMatt T Heffron7-Jan-13 12:03 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 12:12
Member 97041537-Jan-13 12:12 
AnswerRe: Boolean function to return true/false Pin
Matt T Heffron7-Jan-13 12:29
professionalMatt T Heffron7-Jan-13 12:29 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 12:39
Member 97041537-Jan-13 12:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.