日期:2014-05-17 浏览次数:20775 次
//以下的 SQL语句 用得正确吗? 可以用"@dataTable" 这样的参数吗? public bool delEmailAccount(int nodeId, string dataTable, string userName) { OleDbParameter[] parameters = { new OleDbParameter("@dataTable",dataTable), new OleDbParameter("@nodeId", nodeId), // new OleDbParameter("@userName", userName), }; return DBhelper.ExecuteNonqueryBool("delete from @dataTable where id=@nodeId", parameters); }
//为什么以下的语句操作不了数据库的数据? public bool delEmailAccount(int nodeId, string dataTable, string userName) { OleDbParameter[] parameters = { //这里为什么就不能用下面的参数方式来执行操作呢? //new OleDbParameter("@dataTable",dataTable), new OleDbParameter("@nodeId", nodeId), // new OleDbParameter("@userName", userName), }; return DBhelper.ExecuteNonqueryBool("delete from " + dataTable + " where id=@nodeId", parameters); } //而以下的语句却可以呢? public bool delEmailAccount(int nodeId, string dataTable, string userName) { OleDbParameter[] parameters = { //new OleDbParameter("@dataTable",dataTable), // new OleDbParameter("@nodeId", nodeId), // new OleDbParameter("@userName", userName), }; return DBhelper.ExecuteNonqueryBool("delete from " + dataTable + " where id=" + nodeId, parameters); }
//添加搜索结果到数据库 public bool addToDataBase(emailSearchSys_model model) { OleDbParameter[] parameters = { new OleDbParameter("@CustomerEmail", model.CustomerEmail), new OleDbParameter("@CustomerPhone", model.CustomerPhone), new OleDbParameter("@CustomerNote", model.CustomerNote), new OleDbParameter("@categoryId", model.CategoryId), new OleDbParameter("@categoryName", model.CategoryName), new OleDbParameter("@userName", model.UserName), }; return DBhelper.ExecuteNonqueryBool("insert into CustomerData (email,phone,cmsNote,categoryId,categoryName,userName)" +"values (@CustomerEmail,@CustomerPhone,@CustomerNote,@categoryId,@categoryName,@userName)", parameters); }