I have downloaded the file from the following link UK List ods file link and used the following piece of code to convert this ods file to a data set.
int count = 0;
int list_clear = 1;
string connectionString;
if (ConfigurationManager.AppSettings["OperatingSystem"] == "64Bits")
connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + location + ";Extended Properties=\"Excel 12.0;\"";
else
connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
location + @";Extended Properties=""Excel 8.0;HDR=YES;""";
int recCount = 0;
string xmlData = "";
// Create a factory
DbProviderFactory factory =
DbProviderFactories.GetFactory("System.Data.OleDb");
// Create an adapter
DbDataAdapter adapter = factory.CreateDataAdapter();
// Create a select command to get the dataset
DbCommand selectCommand = factory.CreateCommand();
//selectCommand.CommandText = "SELECT * FROM [sanctionsconlist$]";
selectCommand.CommandText = "SELECT * FROM [sheet1$]";// "SELECT * FROM [Data$]";
// Set up the connection and the connection string
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connectionString;
selectCommand.Connection = connection;
// Set up the command
adapter.SelectCommand = selectCommand;
// Create the dataset
DataSet ds = new DataSet();
DataSet dsData = new DataSet();
// Load the results
adapter.Fill(ds);
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStringName"].ConnectionString);
cmd = new SqlCommand();
con.Open();
tran = con.BeginTransaction();
cmd.CommandText = "USP_ImportUKListSanctionListData";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.Transaction = tran;
cmd.Parameters.Add("@xmlData", SqlDbType.NVarChar, -1);
cmd.Parameters.Add("@list_clear_flag", SqlDbType.Int);
cmd.Parameters.Add("@update_list", SqlDbType.Int);
cmd.Parameters.Add("@Error", SqlDbType.Int);
DataTable dt = ds.Tables[0].Clone();
but i get the error, external table is not in the expected format
Can anyone help me in this regard?