Reputation: 2852
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 :
(source: clip2net.com)
Thanks ,
Nikola
Upvotes: 2
Views: 1634
Reputation:
In SqlCe u cannot use directly the parameters I mean the sentence:
string sql = "INSERT INTO posts(user,msg,avatar,date) VALUES(@username,@messige,@userpic,@thedate)";
is wrong. it should be
string sql = "INSERT INTO posts(user,msg,avatar,date) VALUES(?,?,?,?)";
and then followed by:
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();
}
In SqlCe the parameters are passed as "?"
Hope it helps you
Upvotes: 1
Reputation: 300589
Try surrounding 'user' with square brackets, '[user]' (and possibly date).
Upvotes: 7