Budenk
asked on
Add Fields in a table
How to check if a field(column) exists in the table?
Also, How to add the column if it does not exist in the table?
Thank you
Use ADD COLUMN to add a new field to the table. You specify the field name, data type, and (for Text and Binary fields) an optional size. For example, the following statement adds a 25-character Text field called Notes to the Employees table:
ALTER TABLE Employees ADD COLUMN Notes TEXT(25)
You can also define an index on that field. For more information on single-field indexes, see the CONSTRAINT clause topic.
If you specify NOT NULL for a field, then new records are required to have valid data in that field.
ALTER TABLE Employees ADD COLUMN Notes TEXT(25)
You can also define an index on that field. For more information on single-field indexes, see the CONSTRAINT clause topic.
If you specify NOT NULL for a field, then new records are required to have valid data in that field.
ASKER
So, I just need the command object to run that query?
Is there any way that I can use Field Coleections to append the data.
I tried using field collections, but I get this erroe messsage
****************
ADODB.Fields error '800a0c93'
Operation is not allowed in this context.
/fiber/addfield.asp, line 18
*****************
Line 18 : rsX.Fields.Append "Node2", adVariant
Is there any way that I can use Field Coleections to append the data.
I tried using field collections, but I get this erroe messsage
****************
ADODB.Fields error '800a0c93'
Operation is not allowed in this context.
/fiber/addfield.asp, line 18
*****************
Line 18 : rsX.Fields.Append "Node2", adVariant
"Field Collections to append the data"? You lost me...
What are you trying to do?
What are you trying to do?
ASKER
So, I just need the command object to run that query?
Is there any way that I can use Field Coleections to append the data.
I tried using field collections, but I get this erroe messsage
****************
ADODB.Fields error '800a0c93'
Operation is not allowed in this context.
/fiber/addfield.asp, line 18
*****************
Line 18 : rsX.Fields.Append "Node2", adVariant
Is there any way that I can use Field Coleections to append the data.
I tried using field collections, but I get this erroe messsage
****************
ADODB.Fields error '800a0c93'
Operation is not allowed in this context.
/fiber/addfield.asp, line 18
*****************
Line 18 : rsX.Fields.Append "Node2", adVariant
ASKER
First, I would like to check if the field exists.
I use field collections for doing this check.
Then, if the field does not exist, I add a new field.
I am trying to use field collection also for this action.
I use append method as I typed above.
Am I using wrong way?
I use field collections for doing this check.
Then, if the field does not exist, I add a new field.
I am trying to use field collection also for this action.
I use append method as I typed above.
Am I using wrong way?
ASKER
First, I would like to check if the field exists.
I use field collections for doing this check.
Then, if the field does not exist, I add a new field.
I am trying to use field collection also for this action.
I use append method as I typed above.
Am I using wrong way?
I use field collections for doing this check.
Then, if the field does not exist, I add a new field.
I am trying to use field collection also for this action.
I use append method as I typed above.
Am I using wrong way?
You mean like this?
RS.CursorLocation = adUseClient
RS.Fields.Append "Name", adBSTR
RS.Fields.Append "City", adBSTR
RS.Open
RS.AddNew
RS.CursorLocation = adUseClient
RS.Fields.Append "Name", adBSTR
RS.Fields.Append "City", adBSTR
RS.Open
RS.AddNew
ASKER
First, I would like to check if the field exists.
I use field collections for doing this check.
Then, if the field does not exist, I add a new field.
I am trying to use field collection also for this action.
I use append method as I typed above.
Am I using wrong way?
I use field collections for doing this check.
Then, if the field does not exist, I add a new field.
I am trying to use field collection also for this action.
I use append method as I typed above.
Am I using wrong way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
First, I would like to check if the field exists.
I use field collections for doing this check.
Then, if the field does not exist, I add a new field.
I am trying to use field collection also for this action.
I use append method as I typed above.
Am I using wrong way?
I use field collections for doing this check.
Then, if the field does not exist, I add a new field.
I am trying to use field collection also for this action.
I use append method as I typed above.
Am I using wrong way?
ASKER
MGFranz,
That's what I meant with Field Collections.
Does that method work?
I already tried using Alter Table as you suggested, but I got this error:
************
Microsoft OLE DB Provider for SQL Server error '80040e14'
User does not have permission to perform this operation on table 'PCLinks'.
*************
I gave full permission to Public in SQL Server, but I still have the same error message.
What's wrong?
Thank you
That's what I meant with Field Collections.
Does that method work?
I already tried using Alter Table as you suggested, but I got this error:
************
Microsoft OLE DB Provider for SQL Server error '80040e14'
User does not have permission to perform this operation on table 'PCLinks'.
*************
I gave full permission to Public in SQL Server, but I still have the same error message.
What's wrong?
Thank you
Hmm...
ASKER
MGFranz,
That's what I meant with Field Collections.
Does that method work?
I already tried using Alter Table as you suggested, but I got this error:
************
Microsoft OLE DB Provider for SQL Server error '80040e14'
User does not have permission to perform this operation on table 'PCLinks'.
*************
I gave full permission to Public in SQL Server, but I still have the same error message.
What's wrong?
Thank you
That's what I meant with Field Collections.
Does that method work?
I already tried using Alter Table as you suggested, but I got this error:
************
Microsoft OLE DB Provider for SQL Server error '80040e14'
User does not have permission to perform this operation on table 'PCLinks'.
*************
I gave full permission to Public in SQL Server, but I still have the same error message.
What's wrong?
Thank you
ASKER
MGFranz,
That's what I meant with Field Collections.
Does that method work?
I already tried using Alter Table as you suggested, but I got this error:
************
Microsoft OLE DB Provider for SQL Server error '80040e14'
User does not have permission to perform this operation on table 'PCLinks'.
*************
I gave full permission to Public in SQL Server, but I still have the same error message.
What's wrong?
Thank you
That's what I meant with Field Collections.
Does that method work?
I already tried using Alter Table as you suggested, but I got this error:
************
Microsoft OLE DB Provider for SQL Server error '80040e14'
User does not have permission to perform this operation on table 'PCLinks'.
*************
I gave full permission to Public in SQL Server, but I still have the same error message.
What's wrong?
Thank you
ASKER
MGFranz,
That's what I meant with Field Collections.
Does that method work?
I already tried using Alter Table as you suggested, but I got this error:
************
Microsoft OLE DB Provider for SQL Server error '80040e14'
User does not have permission to perform this operation on table 'PCLinks'.
*************
I gave full permission to Public in SQL Server, but I still have the same error message.
What's wrong?
Thank you
That's what I meant with Field Collections.
Does that method work?
I already tried using Alter Table as you suggested, but I got this error:
************
Microsoft OLE DB Provider for SQL Server error '80040e14'
User does not have permission to perform this operation on table 'PCLinks'.
*************
I gave full permission to Public in SQL Server, but I still have the same error message.
What's wrong?
Thank you
Please use 'Reload Question' from top right corner and don't keep pressing F5/Refresh.
Fields collection cannot be appended as you are trying to do.
You might be connecting to a SQL server as a different user from Query Analyzer and yet another user when connecting from ASP. See your connect string for details.
Fields collection cannot be appended as you are trying to do.
You might be connecting to a SQL server as a different user from Query Analyzer and yet another user when connecting from ASP. See your connect string for details.
This question appears to have been abandoned. Please come back to this question and do the necessary evaluation or feedback. I will invite a Moderator to close this question if there's no reply from you after seven days.
I suggest
<points to mgfranz>
for his efforts
** PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER **
hongjun
I suggest
<points to mgfranz>
for his efforts
** PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER **
hongjun
Dear expert(s),
A request has been made to delete this Q in CS:
https://www.experts-exchange.com/questions/20411933/Delete-my-questions.html
Without a response in 72 hrs, a moderator will finalize this question by:
- assigning the points to mgfranz
When you agree or disagree, please add a comment here.
Thank you.
modulo
Community Support Moderator
Experts Exchange
A request has been made to delete this Q in CS:
https://www.experts-exchange.com/questions/20411933/Delete-my-questions.html
Without a response in 72 hrs, a moderator will finalize this question by:
- assigning the points to mgfranz
When you agree or disagree, please add a comment here.
Thank you.
modulo
Community Support Moderator
Experts Exchange
I guess it is only fair to assign points to mgfranz if Budenk fail to reply within the 72 hours grace time.
hongjun
hongjun
Finalized as proposed
modulo
Community Support Moderator
Experts Exchange
modulo
Community Support Moderator
Experts Exchange
Great
Description
table
The name of the table to be altered.
field
The name of the field to be added to or deleted from table.
type
The data type of field.
size
The field size in characters (Text and Binary fields only).
index
The index for field. See the CONSTRAINT clause topic for more information on how to construct this index.
multifieldindex
The definition of a multiple-field index to be added to table. See the CONSTRAINT clause topic for more information on how to construct this clause.
indexname
The name of the multiple-field index to be removed.