Wrox Programmer Forums
|
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
 
Old December 14th, 2003, 04:47 AM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default "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,

 
Old December 14th, 2003, 10:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old December 14th, 2003, 05:08 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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,


 
Old December 15th, 2003, 07:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

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?

 
Old December 15th, 2003, 08:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old December 15th, 2003, 07:22 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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,


 
Old December 15th, 2003, 07:28 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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,


 
Old December 15th, 2003, 07:40 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your advice. I found bugs. I messed up the SQL statement.

Thank you very much,






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert " ". Somesh XML 1 March 6th, 2007 01:30 PM
How to insert " ". Somesh C# 1 March 6th, 2007 08:45 AM
insert into U.N.C.L.E. SQL Language 3 June 6th, 2006 06:35 PM
trigger to insert current date on insert kev_79 SQL Server 2000 3 January 23rd, 2006 05:58 PM
Insert into jemacc SQL Server 2000 2 March 31st, 2004 08:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.