I am creating a Library project which looks up filesystem locations in an Access table.
Everything was working as expected, but then I tried switching my Locations Library's main method to static...now I can't seem to get it to work at all, even after switching it back.
When I check the value of the 'SQL_Query' variable in debug mode it is:
"Select Path From Locations Where Location_ID = Data_Files_Database"
It should be (and was when it was working):
"Select Path From Locations Where Location_ID = 10"
This was not happening before, and I'm not sure why it's happening now nor how to change it back.
I am calling it from another class in this manner:
When I access the enumeration then call the method with an enum as parameter, the parameter is evaluated as the enumeration member's *LABEL*, rather than its integer value.
Thanks!
Everything was working as expected, but then I tried switching my Locations Library's main method to static...now I can't seem to get it to work at all, even after switching it back.
When I check the value of the 'SQL_Query' variable in debug mode it is:
"Select Path From Locations Where Location_ID = Data_Files_Database"
It should be (and was when it was working):
"Select Path From Locations Where Location_ID = 10"
This was not happening before, and I'm not sure why it's happening now nor how to change it back.
I am calling it from another class in this manner:
Code:
Locations locations = new Locations();
string data_Files_Database = locations.GetLocationPath(Locations.Location.Data_Files_Database);
When I access the enumeration then call the method with an enum as parameter, the parameter is evaluated as the enumeration member's *LABEL*, rather than its integer value.
Code:
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Text;
namespace LocationsLibrary
{
public class Locations
{
public enum Location
{
Archive_OldFormat = 1,
Archive_Original = 2,
Uploads = 4,
CDsToBurn = 5,
CurrentProjects = 9,
Data_Files_Database = 10,
DataFiles_ToBeProcessed = 12,
DataFilesLog = 14,
ConversionDatabase = 16,
SpecialFiles = 17,
FTP = 18,
FTP_Uploads = 19,
TargetDB = 21,
FTP_Files = 22,
FTP_Incoming_Files = 23
}
public string GetLocationPath(Location location)
{
//DataProvider enumDataProvider, string dataSourceLocation, string SQL_Query
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = \\MyPC\C$\WorkingFolder\Archive\Locations.mdb";
string scalarReturned = "";
string SQL_Query = "Select Path From Locations Where Location_ID = " + location;
try
{
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand command = new OleDbCommand(SQL_Query, connection);
command.CommandTimeout = 0;
scalarReturned = command.ExecuteScalar().ToString();
}
catch (Exception ex)
{
//ToDo: Implement ErrorHandlerLibrary!
}
return scalarReturned;
}
}
}
Thanks!