Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 14th, 2003, 04:47 AM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Location: , , .
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,

Reply With Quote
  #2 (permalink)  
Old December 14th, 2003, 10:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
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
Reply With Quote
  #3 (permalink)  
Old December 14th, 2003, 05:08 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Location: , , .
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,


Reply With Quote
  #4 (permalink)  
Old December 15th, 2003, 07:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
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?

Reply With Quote
  #5 (permalink)  
Old December 15th, 2003, 08:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
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
Reply With Quote
  #6 (permalink)  
Old December 15th, 2003, 07:22 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Location: , , .
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,


Reply With Quote
  #7 (permalink)  
Old December 15th, 2003, 07:28 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Location: , , .
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,


Reply With Quote
  #8 (permalink)  
Old December 15th, 2003, 07:40 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Location: , , .
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,

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:33 AM.


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