Dot net(SqlCe)

manal -  
 Wens -
Bonjour,
je n'arrive pas à creer une table sur sqlCe a l'aide de c#,apparement j'ai 1 prob avec le chemin de la table.est ce que qq1 peut m'aider?
A voir également:

1 réponse

Wens
 
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;
}
0