插入时解析查询时出错

时间:2014-02-19 23:12:22

标签: c#

尝试使用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 个答案:

答案 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();
        }