1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
try
{
String ConnectionString;
ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathFile + ";Extended Properties=dBase IV";
System.Data.OleDb.OleDbConnection dBaseConnection = new System.Data.OleDb.OleDbConnection(ConnectionString);
dBaseConnection.Open();
System.Data.OleDb.OleDbCommand dBaseCommand = new System.Data.OleDb.OleDbCommand(@"SELECT * FROM [" + safeFileName + "]", dBaseConnection);
System.Data.OleDb.OleDbDataReader dBaseDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SchemaOnly);
if (dBaseDataReader != null)
{
int i = 0;
while (true)
{
try
{
switch (dBaseDataReader.GetDataTypeName(i))
{
case "DBTYPE_WVARCHAR":
Console.WriteLine("string : " + dBaseDataReader.GetName(i));
Console.WriteLine("taille : ");
break;
case "DBTYPE_R8":
Console.WriteLine("int : " + dBaseDataReader.GetName(i));
break;
default:
MessageBox.Show("Certaine données du shapefile sont non suprotées", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
i++;
}
catch (IndexOutOfRangeException)
{
dBaseDataReader = null;
dBaseConnection.Close();
return;
}
catch(Exception exc)
{
MessageBox.Show("L'erreur suivante c'est produite : " + exc.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
dBaseDataReader = null;
dBaseConnection.Close();
return;
}
}
}
dBaseDataReader = null;
dBaseConnection.Close();
}
catch (Exception exc)
{
MessageBox.Show("L'erreur suivante c'est produite : " + exc.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
} |
Partager