public static bool CreateDb()
{
try
{
SqlCeEngine engine = new SqlCeEngine("Data Source =Storage Card/CG.sdf ");
engine.CreateDatabase();
SqlCeConnection ssceconn = new SqlCeConnection("Data Source =Storage Card/CG.sdf ");
ssceconn.Open();
SqlCeCommand sqlCreateTable = ssceconn.CreateCommand();
sqlCreateTable.CommandText = "CREATE TABLE ZYK(Id int IDENTITY(0,1) PRIMARY KEY,Title nvarchar(40), ISBN nvarchar(16),BookNum int,RDate nvarchar(10))";
sqlCreateTable.ExecuteNonQuery();
sqlCreateTable.CommandText = "CREATE TABLE YDK(Id int IDENTITY(0,1) PRIMARY KEY,ShuShang nvarchar(30), ISBN nvarchar(16),BookNum int,RDate datetime)";
sqlCreateTable.ExecuteNonQuery();
sqlCreateTable.CommandText = "Create index ISBN_Idx on ZYK(ISBN)";
sqlCreateTable.ExecuteNonQuery();
sqlCreateTable.CommandText = "Create index ISBN_Idx on YDK(ISBN)";
sqlCreateTable.ExecuteNonQuery();
ssceconn.Close();
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 獲取連接
/// </summary>
/// <returns></returns>
public static void GetConn()
{
if (File.Exists("Storage Card/CG.sdf") == false)
{
Mc.CreateDb();
}
if (Mc.gConn == null)
{
Mc.gConn = new SqlCeConnection("Data Source =Storage Card/CG.sdf ");
Mc.gConn.Open();
}
}