Search code examples
.netado.netsql-server-ce

Whats wrong with this SQLCe Query?


in the past hour i have been trying different variants of this query but i get error at the username , and the username is just a normal string with username that i get from xml file containing no special characters or whatsoever

I'm using SLQ compact 3.5

P.S i tried to use ? instead of @username also not working all feilds are "nchar" except "date"

                C = nodeItem["user_from"].InnerText;
                avatar = nodeItem["user_from_avatar"].InnerText;
                string msgText = nodeItem["message"].InnerText;
                DateTime dt=DateTime.Now;

                string sql = "INSERT INTO posts(user,msg,avatar,date) VALUES(@username,@messige,@userpic,@thedate)";
                using (SqlCeCommand cmd = new SqlCeCommand(sql, connection))
                {
                    cmd.Parameters.Add("@username",C);
                    cmd.Parameters.Add("@messige", msgText.ToString());
                    cmd.Parameters.Add("@userpic", avatar.ToString());
                    cmd.Parameters.Add("@thedate", dt);
                    connection.Open();
                    cmd.ExecuteNonQuery();
                    adapter.Update(data);
                    connection.Close();
                }

The error msg : alt text
(source: clip2net.com)
Thanks , Nikola


Solution

  • Try surrounding 'user' with square brackets, '[user]' (and possibly date).