0
Answer

c# SQLCE Create Table

Daniel Morais

Daniel Morais

10y
2.1k
1
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