Click here to Skip to main content
15,917,568 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey guys, I'm having this problem I can't figure out and I'm wondering if any of you could help?
There was an error parsing the query. [ Token line number = 1,Token line offset = 9,Token in error = Otazky ]
This shows up when I'm trying to update table "Otazky"

C#
ing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlServerCe;
using System.Data;
using System.Windows.Forms;

namespace hra
{
    static class SQLFunctions
    {
        static private SqlCeConnection cecon = new SqlCeConnection(@"Data Source=D:\blbosti\škola\bakalárska práca\hra\hra\Data.sdf");
        
        static public void InsertOtazka(int _ID, string _Otazka, string _SOdp)
        {
            try
            {
                cecon.Open();
                SqlCeCommand insert = new SqlCeCommand("INSERT INTO [Otazky] (Otazka, SOdp, ID) VALUES(@Otazka, @SOdp, @ID)", cecon);
                insert.Parameters.AddWithValue("@Otazka", _Otazka);
                insert.Parameters.AddWithValue("@ID", _ID);
                insert.Parameters.AddWithValue("@SOdp", _SOdp);

                insert.ExecuteNonQuery();
                MessageBox.Show("Otazka ulozena!");
            }

            catch (SqlCeException ex)
            {
                MessageBox.Show(ex.ToString());
            }

            finally
            {
                cecon.Close();
            }
        }


static public void InsertZlaOdpoved(int _ID, string _NOdp, string _pom)
        {
            try
            {
                cecon.Open();
                SqlCeCommand insert = new SqlCeCommand(@"UPDATE Otazky SET NOdp1 = @NOdp WHERE ID LIKE @ID", cecon);
                insert.Parameters.AddWithValue("@NOdp", _NOdp);
                insert.Parameters.AddWithValue("@ID", _ID);
                insert.ExecuteNonQuery();
                MessageBox.Show("Zla odpoved ulozena!");
                
            }

            catch (SqlCeException ex)
            {
                MessageBox.Show(ex.ToString());
            }

            finally
            {
                cecon.Close();
            }
        }
    }
}
Posted
Comments
Kornfeld Eliyahu Peter 16-Feb-15 8:26am    
The INSERT INTO statement works?
See the differences...
somandy333 16-Feb-15 8:29am    
yes, INSERT INTO works perfectly, just the update doesn't .. I Insert 3 columns out of 8, and other 5 are left with null and when I try to update those nulls this error shows up ..
Kornfeld Eliyahu Peter 16-Feb-15 8:32am    
In your INSERT INTO you used Otazky in brackets, try the same for UPDATE...
(Even it is not a reserved word)
somandy333 16-Feb-15 8:35am    
I tried that and many other things, it still doesn't work ..
Kornfeld Eliyahu Peter 16-Feb-15 8:38am    
Just spotted! Why the @ before the UPDATE string?

1 solution

thank you Kornfeld Eliyahu Peter

C#
cecon.Open();
                SqlCeCommand insert = new SqlCeCommand("UPDATE [Otazky] SET NOdp1 = @NOdp WHERE ID = @ID", cecon);
                insert.Parameters.AddWithValue("@NOdp", _NOdp);
                insert.Parameters.AddWithValue("@ID", _ID);
                insert.ExecuteNonQuery();
                MessageBox.Show("Zla odpoved ulozena!");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900