August 16, 2014 at 11:19 am
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)
August 16, 2014 at 12:36 pm
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...
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply