 |
| SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 14th, 2003, 04:47 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
"INSERT INTO"
When I insert only one value, I set the SQL statement as "INSERT INTO ProjectType (ProjectTypeName) VALUES ( 'Birthday Party' )" , but I got an error message that says "missing operation."
I researched the INSERT statement, but I couldn't find the case which insert only one value. Could you tell me about the SQL statement?
Thanks,
|
|

December 14th, 2003, 10:13 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Your INSERT statement syntax is correct.
Give us some more details. For example, how is your 'ProjectType' table defined? Are there more columns in there than 'ProjectTypeName'? If there are, and they are defined to not allow a NULL value, and you have no default constraint defined for those columns, then your INSERT will fail.
Remember that the INSERT statement (with the VALUES clause) inserts one entire row into the table, so you must provide values for those columns which require them.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
|
|

December 14th, 2003, 05:08 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, you're right. The ProjectType table has "ProjectTypeCode" (AutoNumber: ID) and the "ProjectTypeeName" (string). In this case, how can I set the ProjectTypeCode? It's the Autonumber, so I don't know which number will be.
Thanks,
|
|

December 15th, 2003, 07:38 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If the only field apart from ProjectTypeName i an autonumber, your INSERT-statement should be correct - but it might be a typo...
Is the field named ProjectTypeName or ProjectTypeeName?
|
|

December 15th, 2003, 08:38 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Generally, you cannot provide a value for an autonumber/identity column, so if your table only contains the two columns you indicate, your INSERT is correct; the system will automatically assign a value to the autonumber/identity column.
Something else must be going on, then. You'll need to provide more details.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
|
|

December 15th, 2003, 07:22 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry for confusing you about the typo of "ProjectTypeeName."
The error message says, "Missing semicolon (;) at end of SQL statement." That occurs at the ExecuteNonQuery();.
The SQL statement is:
string strProjectTypeSQL = "INSERT INTO ProjectType (ProjectTypeName) ";
strProjectTypeSQL += @"VALUES ( '" + ProjectTypeName+ "' )";
And, it executes like this:
OleDbCommand myProjectTypeCommand = new OleDbCommand(strProjectTypeSQL,myConnection);..... ...
myConnection.Open();...........
myProjectTypeCommand.ExecuteNonQuery();
There're some codes between the lines. I hope that has enough information.
Thank you,
|
|

December 15th, 2003, 07:28 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Besides, I found oledbErrors says, Item <cannot view indexed property> System.Data.OleDb.OleDbError
source "Microsoft JET Database Engine" string
ErrorCode -2147217900 int.
I hope it helps.
Thanks,
|
|

December 15th, 2003, 07:40 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you for your advice. I found bugs. I messed up the SQL statement.
Thank you very much,
|
|
 |