Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 April 21st, 2005, 09:00 AM
Registered User
 
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Syntax error - C# data insert

Syntax error (missing operator) in query expression 'Test Company','Address','Shipping','Houston','000-000-0000','sales@testcoy.com)'.

Here is the code:

        //[STAThread]
        static void Main()
        {
        Application.Run(new StockPile());
        }

        private void StockPile_Load(object sender, System.EventArgs e)
        {
            myOleDbConn = new OleDbConnection(System.Configuration.Configuration Settings.AppSettings.Get("ConnectionString"));
        }

        private void tabCoyInfo_Click(object sender, System.EventArgs e)
        {

        }

        private void btnSave_Click(object sender, System.EventArgs e)
        {
            OleDbCommand myOleDbCommand = new OleDbCommand();
            // Open the connection
            myOleDbConn.Open();
            //Assign the connection property.
            myOleDbCommand.Connection=myOleDbConn;
            try
            {
                // Insert new company
                myOleDbCommand.CommandText = "INSERT INTO CompanyInfo (coyName, coySymbol, coyBusType, coyLocation, coyPhone, coyEMail) VALUES ("+txtCoyName.Text+"','"+txtSymbol.Text+"','"+txtB usType.Text+"','"+txtLocation.Text+"','"+txtPhone. Text+"','"+txtEmail.Text+")";
                myOleDbCommand.ExecuteNonQuery();
                MessageBox.Show("New Customer data recorded!");
            }
            catch(Exception ex)
            {
                MessageBox.Show("Error occurred, customer data could not be recorded: " + ex.Message);
            }
            finally
            {
                // Close the connection if it is open
                if (myOleDbConn.State==ConnectionState.Open)
                {
                    myOleDbConn.Close();
                }
            }
        }

 
Old April 21st, 2005, 10:10 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You are missing 2 '. At the beginning and end of the VALUES() section.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error when using "Insert Into" Luis Access VBA 14 November 18th, 2008 03:09 PM
Syntax Error on Insert dalezjc Classic ASP Basics 29 June 20th, 2007 06:50 PM
"Syntax error in INSERT INTO statement" jtmerchant Classic ASP Databases 1 April 12th, 2006 02:30 PM
Syntax error INSERT INTO ITladybug ADO.NET 2 January 31st, 2006 07:50 AM
INSERT syntax error ss2003 PHP Databases 1 October 7th, 2004 05:30 PM





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