2014-02-19 39 views
-2

得到錯誤時嘗試變量插入到數據庫,使用Visual Studio 2012,數據庫類型SDF有一個錯誤解析查詢時插入

代碼是:

static public void InsertMember(String _MemberId, String _Surname, String _Forename, String _Phonenumber, String _Email, String _Country, String _CityTown, String _CountyZipCode) 
    { 
     try 
     { 
      connection.Open(); 
      SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Members] VALUES(@MemberID, @Surname, @Forename, @Phonenumber, @Email, @Country, @CityTown, @CountyZipCode,)", connection); 
      commandInsert.Parameters.AddWithValue("@MemberID", _MemberId);  
      commandInsert.Parameters.AddWithValue("@Surname", _Surname); 
      commandInsert.Parameters.AddWithValue("@Forename", _Forename); 
      commandInsert.Parameters.AddWithValue("@Phonenumber", _Phonenumber); 
      commandInsert.Parameters.AddWithValue("@Email", _Email); 
      commandInsert.Parameters.AddWithValue("@Country", _Country); 
      commandInsert.Parameters.AddWithValue("@CityTown", _CityTown); 
      commandInsert.Parameters.AddWithValue("@CountyZipCode", _CountyZipCode); 
      commandInsert.ExecuteNonQuery(); 


     } 
     catch (SqlCeException exeptions) 
     { 
      MessageBox.Show(exeptions.ToString()); 

     } 
     finally 
     { 
      connection.Close(); 
     } 
+1

你會得到哪個錯誤?你能從命令文本中刪除最後一個「**,**」嗎? – thepirat000

+0

最後沒有額外的逗號嗎? –

回答

0

試試這個。最後你有一個額外的逗號。

 
static public void InsertMember(String _MemberId, String _Surname, String _Forename, String _Phonenumber, String _Email, String _Country, String _CityTown, String _CountyZipCode) 
    { 
     try 
     { 
      connection.Open(); 
      SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Members] VALUES(@MemberID, @Surname, @Forename, @Phonenumber, @Email, @Country, @CityTown, @CountyZipCode)", connection); 
      commandInsert.Parameters.AddWithValue("@MemberID", _MemberId);  
      commandInsert.Parameters.AddWithValue("@Surname", _Surname); 
      commandInsert.Parameters.AddWithValue("@Forename", _Forename); 
      commandInsert.Parameters.AddWithValue("@Phonenumber", _Phonenumber); 
      commandInsert.Parameters.AddWithValue("@Email", _Email); 
      commandInsert.Parameters.AddWithValue("@Country", _Country); 
      commandInsert.Parameters.AddWithValue("@CityTown", _CityTown); 
      commandInsert.Parameters.AddWithValue("@CountyZipCode", _CountyZipCode); 
      commandInsert.ExecuteNonQuery(); 


     } 
     catch (SqlCeException exeptions) 
     { 
      MessageBox.Show(exeptions.ToString()); 

     } 
     finally 
     { 
      connection.Close(); 
     }