Ask a Question related to ASP Database, Design and Development.
-
Peter Richards #1
Adding a new column in Access
Hi,
Using the following ASP code:
<%
UpdateDB("ALTER TABLE tblConfig ADD SIMVersion varchar(10) NULL AFTER
Version" )
' Subroutine to update the database and check for any errors that
occured
Sub UpdateDB(strSQLCommand)
If Not Application("Debug") Then
On Error Resume Next
End If
If Not blnError Then
cnnDB.Execute (strSQLCommand)
If Err.Number <> 0 Then
blnError = True
intErrorNum = Err.Number
strErrorDesc = Err.Description
strErrorSrc = Err.Source
strErrorCmd = strSQLCommand
Err.Clear
End If
End If
End Sub
%>
.... results in the error msg:
Number: -2147217900
Source: Microsoft JET Database Engine
Description: Syntax error in ALTER TABLE statement.
Ideally, I want to add the new column AFTER a specific column. I note
you can do this in Fox Pro, MySQL, so thought I could do it in ASP for
Access or SQL Server ?
Peter
Peter Richards Guest
-
adding on a column...
How do I make a text box two columns? When I use the create guides feature, the text does not reflow. ( typed in rows 1 and columns 2 ) What am... -
adding a column with data
How do I add a new column with data to an existing table, ensuring correct record matching, using SQL? Situation: I have a table named... -
adding column values
My problem is how to add dataset component given column values (number values) - for example values from PRICE column to have a total amount... -
Adding a select column...
Hi folks, I am aiming to create a "select" column that is unbound on datagrid whose other columns are all data bound. The idea is to let the... -
Convert an MS Access Yes/No column to a checkbox column in C# datagrid
Currently I have a datagrid displaying the multiple columns of data (text and numerical) found in a table in MS Access. In the Access table,... -
Ray at #2
Re: Adding a new column in Access
I'm sure someone will correct me if I'm wrong, but I don't believe you can
specify "after columnname" when you add a column in Access. It'll just get
added to the end. So, this would work, although it won't do exactly what
you want.
UpdateDB("ALTER TABLE tblConfig ADD SIMVersion varchar(10) NULL" )
Ray at home
--
Will trade ASP help for SQL Server help
"Peter Richards" <jehoshua@my-deja.com> wrote in message
news:8ttbivkppd2ehscto52l50a5d6uuck9c12@4ax.com...> Hi,
>
> Using the following ASP code:
>
> <%
> UpdateDB("ALTER TABLE tblConfig ADD SIMVersion varchar(10) NULL AFTER
> Version" )
>
> ' Subroutine to update the database and check for any errors that
> occured
> Sub UpdateDB(strSQLCommand)
> If Not Application("Debug") Then
> On Error Resume Next
> End If
> If Not blnError Then
> cnnDB.Execute (strSQLCommand)
> If Err.Number <> 0 Then
> blnError = True
> intErrorNum = Err.Number
> strErrorDesc = Err.Description
> strErrorSrc = Err.Source
> strErrorCmd = strSQLCommand
> Err.Clear
> End If
> End If
> End Sub
> %>
> ... results in the error msg:
>
> Number: -2147217900
> Source: Microsoft JET Database Engine
> Description: Syntax error in ALTER TABLE statement.
>
> Ideally, I want to add the new column AFTER a specific column. I note
> you can do this in Fox Pro, MySQL, so thought I could do it in ASP for
> Access or SQL Server ?
>
> Peter
>
Ray at Guest
-
Ray at #3
Re: Adding a new column in Access
Yeah, same with Enterprise Manager. Obviously that's executing some t-sql
that's doing what you want. Hmm, I wonder if there's a T-SQL sniffer that I
can find. ;] I won't be surpised if someone else posts with a better
solution that will allow you to insert the column in the position you want.
Ray at home
--
Will trade ASP help for SQL Server help
"Peter Richards" <jehoshua@my-deja.com> wrote in message
news:ocvbivgltqscgm303dthemor70bptcek39@4ax.com...can> Hi Ray,
>
> On Tue, 29 Jul 2003 00:49:48 -0400, "Ray at <%=sLocation%>"
> <myfirstname at lane34 dot com> wrote:
>> >I'm sure someone will correct me if I'm wrong, but I don't believe youget> >specify "after columnname" when you add a column in Access. It'll just>> >added to the end.
> That's a bother. When I'm using Access interactively, in design mode,
> I can position to a column, and then do an insert, for a new column
> and specify exactly where to place the column.
>>> >So, this would work, although it won't do exactly what
> >you want.
> >
> >UpdateDB("ALTER TABLE tblConfig ADD SIMVersion varchar(10) NULL" )
> Yes, it does.
>
> Thanks,
>
> Peter
>
Ray at Guest
-
Bob Barrows #4
Re: Adding a new column in Access
Ray at <%=sLocation%> wrote:
Yep - just like in Access, a new table is being created with the desired> Yeah, same with Enterprise Manager. Obviously that's executing some
> t-sql that's doing what you want.
column order, then the data from the old table is moved into the new table
and the old table is dropped.
Shouldn't be too hard to find it: it's called SQL Profiler and it can be> Hmm, I wonder if there's a T-SQL
> sniffer that I can find. ;]
found in your Windows Start menu in the SQL Server program group. :-)
Actually, there's an easier way. There's a button you can click in the EM
table designer that allows you to see the script being used to effect the
change.
I would :-)> I won't be surpised if someone else
> posts with a better solution that will allow you to insert the column
> in the position you want.
Using DAO, there's a property called OrdinalPosition, that sets or reads the
relative position of the fields in the table. However, this does not affect
the physical order of the fields: only the order in which the fields will
retrieved when doing a selstar query, which should not be used in production
code, anyways, right? :-)
HTH,
Bob Barrows
Bob Barrows Guest
-
Ray at #5
Re: Adding a new column in Access
It did. Thanks Bob!
Ray at home
> "Bob Barrows"
> HTH,
Ray at Guest
-
Aaron Bertrand - MVP #6
Re: Adding a new column in Access
> Using DAO, there's a property called OrdinalPosition, that sets or reads
theaffect> relative position of the fields in the table. However, this does notReally? Is this true for Access only?> the physical order of the fields: only the order in which the fields will
> retrieved when doing a selstar query,
Aaron Bertrand - MVP Guest
-
Bob Barrows #7
Re: Adding a new column in Access
Aaron Bertrand - MVP wrote:
I'm 90% sure it's only read/write for Jet databases. As I said, it's a DAO>>> Using DAO, there's a property called OrdinalPosition, that sets or
>> reads the relative position of the fields in the table. However,
>> this does not affect the physical order of the fields: only the
>> order in which the fields will retrieved when doing a selstar query,
> Really? Is this true for Access only?
property: it is not available in ADOX. I suspect that it will not have any
effect on queries run by ADO.
Bob
Bob Barrows Guest
-
Peter Richards #8
Re: Adding a new column in Access
Hi,
Thanks everyone for your replies. The bottom line is that it can't be
done in ASP on an Access db.
Peter
Peter Richards Guest
-
Peter Richards #9
Re: Adding a new column in Access
Hi Aaron,
On Tue, 29 Jul 2003 09:17:40 -0400, "Aaron Bertrand - MVP"
<aaron@TRASHaspfaq.com> wrote:
I simply prefer it that way, as I find once a table gets more than>Why does it matter where a column sits?
about 30 columns, from a design point of view, I would prefer an
ordered view of columns, it simply makes sense and makes maintenanance
easier. Being restricted by having to add new columns at the end of
the table moves away from a structured view of the table, even if the
'view' is only a logical one, that would help a lot.
The columns I need to add are adding two more dimensions to a
hierarchy, therefore (for me) from a design point of view, I prefer to
"see" all the hierarchy represented, logically at least (physical
order doesn't concern me) in a meaningful and structured manner.
Yes, rather a painful exercise indeed.>If you want to pull data out of the
>table with columns in a specific order, list them that way in the SELECT
>statement. You shouldn't care about the physical structure... but if you
>want to do it that way, you can do what SQL Server, and surely Access, do:
>create a dummy table with the new column in the correct place, move all the
>data, disable constraints, swap table names, re-enable constraints, and drop
>the original table. Yeah, that sounds like fun.
Peter
Peter Richards Guest
-
Aaron Bertrand [MVP] #10
Re: Adding a new column in Access
> >Why does it matter where a column sits?
Shouldn't you have designed the table from the ground up? As soon as you>
> I simply prefer it that way, as I find once a table gets more than
> about 30 columns, from a design point of view, I would prefer an
> ordered view of columns, it simply makes sense and makes maintenanance
> easier.
start adding columns on the fly after the fact, you can smell lack of good
design... also, once a table gets more than about 30 columns, I think it
has too many columns and some normalization may be in order...
Aaron Bertrand [MVP] Guest
-
Peter Richards #11
Re: Adding a new column in Access
Hi,
On Tue, 29 Jul 2003 21:49:32 -0400, "Aaron Bertrand [MVP]"
<aaron@TRASHaspfaq.com> wrote:
Yes, I wish I had have, but I'm making changes to someone elses>Shouldn't you have designed the table from the ground up?
design, a GNU product. The changes I'm making have been requested by
many people for a year or more, so they (the changes) are long
overdue. But hey, you get what you pay for. :)
I agree.>As soon as you
>start adding columns on the fly after the fact, you can smell lack of good
>design... also, once a table gets more than about 30 columns, I think it
>has too many columns and some normalization may be in order...
Peter
Peter Richards Guest
-
Aaron Bertrand - MVP #12
Re: Adding a new column in Access
> Have you never worked in a changing environment?
Uh, yes. Currently, in fact.
Aaron Bertrand - MVP Guest



Reply With Quote

