sql语句字符串拼接的两种方法 SQL Server

            String ProductionProduct = temp.Rows[i][3].ToString().Trim();
                    //StringBuilder Sql2 = new StringBuilder();
                    //Sql2.Append("select top 1 [ProductID] from [Product] where [productname] =");
                    //Sql2.Append("N'" + ProductionProduct + "';");
                    //String sql22 = Sql2.ToString();
                    String sql2 = @"select [ProductID] from [Product] where [productname] =N'"+ ProductionProduct+ "'";
                    List< ProductModel > res2 = db.Database.SqlQuery(sql2).ToList();
                    string ProductID = string.Empty;
                    foreach ( ProductModel productname in res2)
                    {
                        ProductID = String.Format( "{0}" , productname.ProductID);
                    }

将数据库中字段为空的赋值为0
update Material set MaterialTypeID='0' where MaterialTypeID='' or MaterialTypeID is NULL

你可能感兴趣的:(零落)