Daniel Morais

Daniel Morais

  • NA
  • 9
  • 7.7k

c# SQLCE Create Table

Nov 27 2013 3:00 PM
I am using this to create my table is this the way to do it, i Need to link the two tables
 /*----------------------------------------------*/
 

static public void CreateTable()
{
  SqlCeConnection cn = new SqlCeConnection(ConnectString());
  if (cn.State == ConnectionState.Closed) 
 {
  cn.Open();
  }
  SqlCeCommand cmd;
  sql="create table Categories ("
  + "CategoryID INT IDENTITY (1,1) CONSTRAINT pkCategoryID PRIMARY KEY not null, "
  + "Categorie nvarchar(50))"; 
 cmd = new SqlCeCommand(sql, cn); 
  cmd.ExecuteNonQuery();
  sql = "create table Snippets (" + "SnippetsID INT IDENTITY (1,1) CONSTRAINT pkCategoryID PRIMARY KEY not null, "
  + "CategoryID INT REFERENCES Categories(CategoryID), "
  + "SnippetsName nvarchar (50), " 
 + "SnippetsContent ntext)"; 
  cmd = new SqlCeCommand(sql, cn);
  cmd.ExecuteNonQuery();
  cn.Close();
}



Thank's