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();
}
}
}
|