2009-12-18 2 views

답변

4

예, 가능합니다. the MSDN page on SqlCeEngine.CreateDatabase에서 인용 :이 후

if (File.Exists("Test.sdf")) 
File.Delete("Test.sdf"); 

string connStr = "Data Source = Test.sdf; Password = <password>;"; 

SqlCeEngine engine = new SqlCeEngine(connStr); 
engine.CreateDatabase(); 
engine.Dispose(); 
SqlCeConnection conn = null; 

try 
{ 
    conn = new SqlCeConnection(connStr); 
    conn.Open(); 

    SqlCeCommand cmd = conn.CreateCommand(); 
    cmd.CommandText = "CREATE TABLE myTable (col1 int, col2 ntext)"; 
    cmd.ExecuteNonQuery(); 
} 

catch {} 

finally 
{ 
    conn.Close(); 
} 

을, 당신은 모바일 장치에 Test.sdf을 복사 만 할 수 있습니다.

희망이 도움이됩니다.

0

작성 하시겠습니까?

Visual Studio에서? 서버 탐색기를 열고 새 데이터 연결을 추가하십시오. SQL Compact를 데이터 원본으로 선택하고 파일 이름을 지정하고 만들기를 클릭합니다.

코드에서? SqlCeEngine 클래스를 사용하십시오. 연결 문자열을 지정하고 Create를 호출하십시오.