2013-11-01 2 views
0

내 오류 : 테이블 chang9가 이미 있습니다.sqlite 테이블을 C에서 이미 삭제 한 후 삭제하는 방법 #

sqlite_cmd.CommandText = " DROP Table 'chang9'"; 

아마와 구문에 문제가있다 : 그래서 내가 (운으로) 사용,

나는 주위에 인터넷 검색, 사람들은 당신이 그것을 실행 한 후 테이블을 삭제한다고? 그러나 여기 내 전체 코드는 다음과 같습니다 :

private void button4_Click(object sender, EventArgs e) 
    { 
     // We use these three SQLite objects: 
     SQLiteConnection sqlite_conn; 
     SQLiteCommand sqlite_cmd; 

     // create a new database connection: // Maybe error here - video was different 
     sqlite_conn = new SQLiteConnection(@"Data Source=database.db;Version=3;"); 

     // open the connection: 
     sqlite_conn.Open(); 

     // create a new SQL command: 
     sqlite_cmd = sqlite_conn.CreateCommand(); 

     // Let the SQLiteCommand object know our SQL-Query: 
     sqlite_cmd.CommandText = "CREATE TABLE chang9 (Seq text, Field text, Desc text, Len text, Dec text, Typ text, Percnt text, Pop text, Alzero text, MaxLen text);"; 

     // Now lets execute the SQL                     
     sqlite_cmd.ExecuteNonQuery(); 

     sqlite_cmd.CommandText = "INSERT INTO chang9 (Seq, Field, Desc, Len, Dec, Typ, Percnt, Pop, Alzero, MaxLen) VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10)"; 
     sqlite_cmd.Parameters.AddWithValue("@p1", 6); // dummy initial values 
     sqlite_cmd.Parameters.AddWithValue("@p2", 878); 
     sqlite_cmd.Parameters.AddWithValue("@p3", 56); 
     sqlite_cmd.Parameters.AddWithValue("@p4", 6); 
     sqlite_cmd.Parameters.AddWithValue("@p5", 546); 
     sqlite_cmd.Parameters.AddWithValue("@p6", 565); 
     sqlite_cmd.Parameters.AddWithValue("@p7", 568); 
     sqlite_cmd.Parameters.AddWithValue("@p8", 526); 
     sqlite_cmd.Parameters.AddWithValue("@p9", 586); 
     sqlite_cmd.Parameters.AddWithValue("@p10", 526); 


     for (int i = 0; i < 500 ; i+= 10) // Filling SQlite table rows and columns with values from our list 
     { 


      sqlite_cmd.Parameters.AddWithValue("@p1", list[i]); 
      sqlite_cmd.Parameters.AddWithValue("@p2", list[i+1]); 
      sqlite_cmd.Parameters.AddWithValue("@p3", list[i + 2]); 
      sqlite_cmd.Parameters.AddWithValue("@p4", list[i + 3]); 
      sqlite_cmd.Parameters.AddWithValue("@p5", list[i + 4]); 
      if (i > 490) 
       break; 
      sqlite_cmd.Parameters.AddWithValue("@p6", list[i + 5]); 
      sqlite_cmd.Parameters.AddWithValue("@p7", list[i + 6]); 
      sqlite_cmd.Parameters.AddWithValue("@p8", list[i + 7]); 
      sqlite_cmd.Parameters.AddWithValue("@p9", list[i + 8]); 
      sqlite_cmd.Parameters.AddWithValue("@p10", list[i + 9]); 
      sqlite_cmd.ExecuteNonQuery(); 

     } 

     sqlite_cmd.CommandText = " DROP Table 'chang9'"; 
     sqlite_conn.Close(); 

    } 

답변

1

아래

+0

안녕하세요, pls 님이 bunyip의 답변에 게시 된 의견을 참조하십시오. 테이블을 생성하지 않고이 테이블을 단순히 어떻게 볼 수 있습니까? 난 그냥 여러 번 프로그램을 실행하고 같은 테이블을 반복해서 볼 수 있어야합니다. – user2788405

1

귀하의 문제가 여기에있다 (참고 드롭 테이블 섹션은 코드의 끝 부분에) :

sqlite_cmd.CommandText = "CREATE TABLE chang9 (Seq text, Field text, Desc text, Len text, Dec text, Typ text, Percnt text, Pop text, Alzero text, MaxLen text);"; 

이미 존재하는 테이블을 생성, 그래서 다시 만들 수는 없습니다.

이 코드를 시작할 때 표가없는 것으로 간주하지만 이미 있습니다. 당신이 당신의 하락 테이블 문에 텍스트를 설정 한 후 당신은 당신의 명령을 실행하지 않는 명령

drop table if exists Table_Name 
1

사용 :

sqlite_cmd.CommandText = " DROP Table 'chang9'"; 
sqlite_conn.Close(); 

같은 테이블이 삭제되고 있지 않습니다 것처럼. 메소드를 다시 실행하려고하면 테이블이 이미 존재하며 사용자가보고있는 오류가 발생합니다. 테이블을 삭제하도록 명령 텍스트를 설정 한 후에 sqlite_cmd.ExecuteNonQuery();과 같은 행을 추가해야합니다.

sqlite_cmd.CommandText = " DROP Table 'chang9'"; 
sqlite_conn.Close(); 
sqlite_cmd.ExecuteNonQuery(); 
+0

테이블이 존재합니다 (따라서 오류가 있습니다). – Mike

+0

예 위 명령을 사용하면 기존 테이블이 삭제됩니다. 그리고 이것이 이것이 질문의 의도라고 생각합니다. – SKJ

+0

테이블이 존재한다고 가정하면'if exists Table_Name'을 추가하는 것은'true'와 동등합니다.이 경우'true'가 항상 통과하고 중단 될 수 있습니다. 표가 존재하지 않으면 오류가 달라집니다. – Mike

관련 문제