A voir également:
- Dot net(SqlCe)
- Net framework 2.0 - Télécharger - Divers Utilitaires
- Paint net - Télécharger - Dessin & Illustration
- Logo .net - Télécharger - Études & Formations
- Comment ouvrir un fichier dot ? - Guide
- Net framework 4.0 - Télécharger - Divers Utilitaires
1 réponse
hello,
Sans precision sur ton code... taider c'est pas de la tarte...
mais bon essaye le code ci dessous, il marche pour moi donc il n'y a pas de raisons.
/// <summary>
/// Create the Data Base if it does not exist
/// </summary>
/// <returns>
/// False if the Data Base was created.
/// True if the DB existed before.
/// </returns>
static public void CreateDB()
{
if (System.IO.File.Exists(sDBPath) == true)
{
System.IO.File.Delete(sDBPath);
SqlCeEngine Engine = new SqlCeEngine(sConnexionLocal);
Engine.CreateDatabase();
Engine.Dispose();
}
else
{
SqlCeEngine Engine = new SqlCeEngine(sConnexionLocal);
Engine.CreateDatabase();
Engine.Dispose();
}
List<string> lSQL = CreateTables();
foreach (string s in lSQL)
ExecuteSQL(s);
}
/// <summary>
/// Execute the given SQL query.
/// </summary>
/// <param name="sSQL"> SQL query to execute </param>
/// <returns>
/// True if successfull, false otherwise.
/// </returns>
static public bool ExecuteSQL(string sSQL)
{
try
{
SqlCeConnection SqlCnx = new SqlCeConnection(sConnexionLocal);
SqlCeCommand SqlCommand = new SqlCeCommand(sSQL, SqlCnx);
SqlCnx.Open();
SqlCommand.Prepare();
SqlCommand.ExecuteNonQuery();
if (SqlCnx.State == ConnectionState.Open)
SqlCnx.Close();
return true;
}
catch (Exception ex)
{
ExceptionHandling.Exceptionlogging(ex);
}
return false;
}
static private List<string> CreateTables()
{
List<string> sSQL = new List<string>();
#region TCLients
sSQL.Add("CREATE TABLE Clients" +
"(" +
"CliRef UNIQUEIDENTIFIER NOT NULL PRIMARY KEY," +
"CliLastName NVARCHAR(255)," +
"CliStreetNum INTEGER," +
"CliBirthDate DATETIME," +
"CliActiv BIT" +
")");
#endregion
return sSQL;
}
Sans precision sur ton code... taider c'est pas de la tarte...
mais bon essaye le code ci dessous, il marche pour moi donc il n'y a pas de raisons.
/// <summary>
/// Create the Data Base if it does not exist
/// </summary>
/// <returns>
/// False if the Data Base was created.
/// True if the DB existed before.
/// </returns>
static public void CreateDB()
{
if (System.IO.File.Exists(sDBPath) == true)
{
System.IO.File.Delete(sDBPath);
SqlCeEngine Engine = new SqlCeEngine(sConnexionLocal);
Engine.CreateDatabase();
Engine.Dispose();
}
else
{
SqlCeEngine Engine = new SqlCeEngine(sConnexionLocal);
Engine.CreateDatabase();
Engine.Dispose();
}
List<string> lSQL = CreateTables();
foreach (string s in lSQL)
ExecuteSQL(s);
}
/// <summary>
/// Execute the given SQL query.
/// </summary>
/// <param name="sSQL"> SQL query to execute </param>
/// <returns>
/// True if successfull, false otherwise.
/// </returns>
static public bool ExecuteSQL(string sSQL)
{
try
{
SqlCeConnection SqlCnx = new SqlCeConnection(sConnexionLocal);
SqlCeCommand SqlCommand = new SqlCeCommand(sSQL, SqlCnx);
SqlCnx.Open();
SqlCommand.Prepare();
SqlCommand.ExecuteNonQuery();
if (SqlCnx.State == ConnectionState.Open)
SqlCnx.Close();
return true;
}
catch (Exception ex)
{
ExceptionHandling.Exceptionlogging(ex);
}
return false;
}
static private List<string> CreateTables()
{
List<string> sSQL = new List<string>();
#region TCLients
sSQL.Add("CREATE TABLE Clients" +
"(" +
"CliRef UNIQUEIDENTIFIER NOT NULL PRIMARY KEY," +
"CliLastName NVARCHAR(255)," +
"CliStreetNum INTEGER," +
"CliBirthDate DATETIME," +
"CliActiv BIT" +
")");
#endregion
return sSQL;
}