1

I have problem regarding insert operation in SQL Server CE, this is the exception

enter image description here

and these are my code :

private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            perintahsql = new SqlCeCommand("INSERT INTO lokasi (Campus, Address, Phone 1, Phone 2, Phone 3, Fax, Ext.number, Longitude, Latitude, Maps) VALUES (@Campus, @Address, @Phone 1, @Phone 2, @Phone 3, @Fax, @Ext.number, @Longitude, @Latitude, @Maps)", koneksi);
            perintahsql.Parameters.AddWithValue("@Campus", comboBox1.Text);
            perintahsql.Parameters.AddWithValue("@Address", textBox1.Text);
            perintahsql.Parameters.AddWithValue("@Phone 1", textBox2.Text);
            perintahsql.Parameters.AddWithValue("@Phone 2", textBox3.Text);
            perintahsql.Parameters.AddWithValue("@Phone 3", textBox4.Text);
            perintahsql.Parameters.AddWithValue("@Fax", textBox5.Text);
            perintahsql.Parameters.AddWithValue("@Ext. number", textBox6.Text);
            perintahsql.Parameters.AddWithValue("@Longitude", textBox7.Text);
            perintahsql.Parameters.AddWithValue("@Latitude", textBox8.Text);
            perintahsql.Parameters.AddWithValue("@Maps", textBox9.Text);
            koneksi.Open();
            perintahsql.ExecuteNonQuery();
            koneksi.Close();
        }
        catch (SqlCeException ex)
        {
            MessageBox.Show("Whoopss!! " + ex, "SQL Server CE Exception Message");
        }
    }

How to fix that error? Thank you.

4

2 に答える 2

1

You cannot have spaces in column names as well as variable names. If you open your insert statement up in notepad++ (or count manually), you'll find that character 44 is the first space in "Phone 1".

"INSERT INTO lokasi (Campus, Address, Phone "

于 2012-09-22T05:34:10.657 に答える
1

Try renaming you variables, SQL doesnot permit variable with spaces. Change variables @Phone 1 as @Phone1 etc and also @Ext. number as @ExtNumber. Hope it will resolve your query.

于 2012-09-22T05:35:08.873 に答える