Search code examples
sqlsyntax-erroralteroledbcommand

Alter Table SQL String - Syntax error


This is a bit of a two part question, firstly the SQL string

Dim Addcolumn As New OleDb.OleDbCommand("ALTER TABLE [" & TableName & "] ADD " & X & "", con)


    X = 0
    Do
        X = X + 1

        Addcolumn.ExecuteNonQuery() 
    Loop Until X = 8

This string is throwing up a syntx error, specifically OleDbException was unhandled, Syntax error is SQL statement

Im not sure where ive gone wrong, done some research but can't find a fault, im sure its obvious to someone with a bit more experience.

My second part of the question is clarification on something I was wondering. If I enter new columns into a data set will it stick when I update the form? Or is it only rows that do that? And if so will creating new columns in the actual table, then copying it to the dat set, then updating the table through a table adapter work? And give me my desired rows and columns for my table?

All help is greatly appreciated

Thanks so much in advance!

Moh =)


Solution

  • you can try

     X = 0
        Do
          Dim Addcolumn As New OleDb.OleDbCommand("ALTER TABLE [" & TableName & "] ADD COLUMN " & X      & " varchar(10) NULL", con)
    
            X = X + 1
    
            Addcolumn.ExecuteNonQuery() 
        Loop Until X = 8