0
我正在使用SQL Server Compact Edition。我尝试从最大日期的数据库中删除数据,我尝试查询它完美的工作,但是当我在我的程序中执行时,转而删除所有不基于我创建的查询的数据。无法使用SQL Server Compact Edition中的条件删除数据
这里是我的代码
string sqlCom="";
sqlCom = " delete from " + tableName; ;
sqlCom += " where messageid not in(";
sqlCom += " select messageid from tabmessageinclient";
sqlCom += " where convert(nvarchar(10),dtmessagetime,101) ";
sqlCom += " in (select max(convert(nvarchar(10),dtmessagetime,101)) from tabmessageinclient))";
SqlCeConnection ceCon = new SqlCeConnection(Properties.Settings.Default.MyConnection);
if (ceCon.State == System.Data.ConnectionState.Open)
{ ceCon.Close(); }
ceCon.Open();
SqlCeCommand cmd = new SqlCeCommand();
cmd.Connection = ceCon;
cmd.CommandText = sqlCom;
cmd.ExecuteNonQuery();
没有人知道什么是错我的代码,遗憾的英语不好
使用@符号在多行上写字符串,目前这对我来说是不可读的。也尝试格式化您的查询... – mybirthname
[SQL注入警报](http://msdn.microsoft.com/en-us/library/ms161953%28v=sql.105%29.aspx) - 你应该**不**将您的SQL语句连接在一起 - 使用**参数化查询**来避免SQL注入 –