Define the columns or fields programmatically from a blank table

  • I have a blank table in ASP.net SQL Data Connection: Table1.

    I want to define the columns or fields programmatically.

    Here is my SQL statement, errors and all:

    cmdStr = "ALTER TABLE [Table1] ADD COLUMN " & myreader(k) & " varchar(50);"

    I want it to add a column for every k: 4 columns, k= 0 to 3, myreader(0),myreader(1),myreader(2) and myreader(3)

  • That doesn't sound like a normalized table structure...

    An normalized table would look more like this:

    CREATE TABLE meaningfulName

    (RowId INT IDENTITY(1,1),

    MyReader varchar(50),

    MyReaderPos INT ,

    CONSTRAINT CX_meaningfulName PRIMARY KEY CLUSTERED (RowId)

    )

    Edit: As you can see, the "loop" for every [k] isn't required at all. The values of [k] will be stored in the column MyReaderPos instead...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply