1

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 =)

2
  • What query are you trying to run? ATM it's ALTER TABLE (TableName) ADD 1..2..3..4.. which isn't valid SQL syntax at all. Commented May 9, 2012 at 23:14
  • @hkf Im trying to create a new column everytime the loop completes. I,m guessing im nowhere near close then? Commented May 9, 2012 at 23:19

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Up voted the question and response because the question was clearly phrased and just seeing the syntax answered my question. Thx!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.