Hi,
I am experiencing irritating error (undiscriptive rather), when I want to insert a single statement into my db.
Following is the code:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString =@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";
SqlCommand dataCommand = new SqlCommand();
dataCommand.CommandText=("INSERT INTO citylist(city_id,city_name,latitude,longitude,state) VALUES ((1, 'Port Blair', '11.67 N', '92.76 E', 'Andaman and Nicobar Islands')");
dataCommand.Connection = dataConnection;
dataConnection.Open();
dataCommand.ExecuteNonQuery();
dataConnection.Close();
}
Following is the error:
Incorrect syntax near ','.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near ','.
Source Error:
Line 46: dataConnection.Open();
Line 47:
Line 48: dataCommand.ExecuteNonQuery();
Line 49: dataConnection.Close();
Line 50:
Source File: c:\Users\sujit\Documents\Visual Studio 2008\WebSites\WebSite1\Default.aspx.cs Line: 48
The similar INSERT statement has been working in one of the other page, but this.
What could be the problem, please?