none
Alter column in Sqlce database error RRS feed

  • Question

  • With this code i trying to put a column in a sdf database.

    Part is working but i get a error , the column is in the database after i push the button . But the error ?

    cmd = New SqlCeCommand("ALTER TABLE Bemanning ADD Paspoort1 NVARCHAR(4000)", con)
            If con.State = ConnectionState.Closed Then con.Open()
            myDA = New SqlCeDataAdapter(cmd)
            myDataSet = New DataSet()
            myDA.Fill(myDataSet, "MyTable")
            
    
            If con.State = ConnectionState.Closed Then con.Open()
    
            cmd.ExecuteNonQuery()

    on this i get the error

    cmd.ExecuteNonQuery()


    An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
    
    Additional information: A column ID occurred more than once in the specification.

    I only have one Id

    Sunday, July 15, 2018 7:43 PM

Answers

  • With this code i trying to put a column in a sdf database.

    Part is working but i get a error , the column is in the database after i push the button . But the error ?

    cmd = New SqlCeCommand("ALTER TABLE Bemanning ADD Paspoort1 NVARCHAR(4000)", con)
            If con.State = ConnectionState.Closed Then con.Open()
            myDA = New SqlCeDataAdapter(cmd)
            myDataSet = New DataSet()
            myDA.Fill(myDataSet, "MyTable")
            
    
            If con.State = ConnectionState.Closed Then con.Open()
    
            cmd.ExecuteNonQuery()

    on this i get the error

    cmd.ExecuteNonQuery()


    An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
    
    Additional information: A column ID occurred more than once in the specification.

    I only have one Id

    The error you are experiencing is telling you that the column you are adding already exists in the table. Probably the first time you did this, you had no error, but every time after that you got errors... You should check to see if the column exists already before trying to add it.

    Hire Me For This Job!
    Don't forget to vote for Helpful Posts and Mark Answers!
    *This post does not reflect the opinion of Microsoft, or its employees.


    Sunday, July 15, 2018 7:53 PM
    Moderator

All replies

  • With this code i trying to put a column in a sdf database.

    Part is working but i get a error , the column is in the database after i push the button . But the error ?

    cmd = New SqlCeCommand("ALTER TABLE Bemanning ADD Paspoort1 NVARCHAR(4000)", con)
            If con.State = ConnectionState.Closed Then con.Open()
            myDA = New SqlCeDataAdapter(cmd)
            myDataSet = New DataSet()
            myDA.Fill(myDataSet, "MyTable")
            
    
            If con.State = ConnectionState.Closed Then con.Open()
    
            cmd.ExecuteNonQuery()

    on this i get the error

    cmd.ExecuteNonQuery()


    An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
    
    Additional information: A column ID occurred more than once in the specification.

    I only have one Id

    The error you are experiencing is telling you that the column you are adding already exists in the table. Probably the first time you did this, you had no error, but every time after that you got errors... You should check to see if the column exists already before trying to add it.

    Hire Me For This Job!
    Don't forget to vote for Helpful Posts and Mark Answers!
    *This post does not reflect the opinion of Microsoft, or its employees.


    Sunday, July 15, 2018 7:53 PM
    Moderator
  • Ahhh now i see why ,

    i removed this.

     cmd.ExecuteNonQuery()

    Now no error and it works .

    Thanks Paul

    Sunday, July 15, 2018 7:56 PM
  • Ahhh now i see why ,

    i removed this.

     cmd.ExecuteNonQuery()

    Now no error and it works .

    Thanks Paul

    Np, but I am not sure how my response prompted you to remove that line of code unless you didn't want to add a column under any circumstance... Or perhaps you used that code just once to create your initial DB. Either way, I am glad you have fixed your error!

    Hire Me For This Job!
    Don't forget to vote for Helpful Posts and Mark Answers!
    *This post does not reflect the opinion of Microsoft, or its employees.


    Sunday, July 15, 2018 8:15 PM
    Moderator