执行此操作时,我的数据库出现问题:
<asp:SqlDataSource ID="SqlDataSourceCombine" runat="server"
ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
DeleteCommand="DELETE FROM [Product] WHERE [ProductId] = @ProductId"
InsertCommand="INSERT INTO [Product] ([ProductName], [ProductDescription], [ProductCategory], [ProductBrand], [ProductPrice], [ProductQty], [ProductUploadDate]) VALUES (@ProductName, @ProductDescription, @ProductCategory, @ProductBrand, @ProductPrice, @ProductQty, @ProductUploadDate)"
SelectCommand="SELECT Product.*, ProductCategory.*, ProductBrand.*
FROM Product
INNER JOIN ProductCategory AS PC ON Product.ProductCategory = ProductCategory.CategoryId
INNER JOIN ProductBrand AS PB ON Product.ProductBrand = ProductBrand.BrandId"
UpdateCommand="UPDATE [Product] SET [ProductName] = @ProductName,
[ProductDescription] = @ProductDescription,
[ProductCategory] = @ProductCategory,
[ProductBrand] = @ProductBrand,
[ProductPrice] = @ProductPrice,
[ProductQty] = @ProductQty,
WHERE [ProductId] = @ProductId">
</asp:SqlDataSource>
我收到此错误:
答案 0 :(得分:0)
您指定的查询中存在多个错误。
Product
,这是错误的语法。因此,请对select命令使用以下查询。SELECT查询
SELECT product.*,
productcategory.*,
productbrand.*
FROM product
INNER JOIN productcategory
ON product.productcategory = productcategory.categoryid
INNER JOIN productbrand
ON product.productbrand = productbrand.brandid
更新查询
UPDATE [product]
SET [productname] = @ProductName,
[productdescription] = @ProductDescription,
[productcategory] = @ProductCategory,
[productbrand] = @ProductBrand,
[productprice] = @ProductPrice,
[productqty] = @ProductQty
WHERE [productid] = @ProductId
您的最终标记应如下所示。
带有更正查询的SqlDataSource
<asp:SqlDataSource ID="SqlDataSourceCombine" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
DeleteCommand="DELETE FROM [Product] WHERE [ProductId] = @ProductId"
InsertCommand="INSERT INTO [Product] ([ProductName], [ProductDescription], [ProductCategory], [ProductBrand], [ProductPrice], [ProductQty], [ProductUploadDate]) VALUES (@ProductName,
@ProductDescription, @ProductCategory, @ProductBrand, @ProductPrice, @ProductQty, @ProductUploadDate)"
SelectCommand="SELECT product.*, productcategory.*,
productbrand.* FROM product
INNER JOIN productcategory
ON product.productcategory = productcategory.categoryid
INNER JOIN productbrand
ON product.productbrand = productbrand.brandid "
UpdateCommand="UPDATE [product]
SET [productname] = @ProductName,
[productdescription] = @ProductDescription,
[productcategory] = @ProductCategory,
[productbrand] = @ProductBrand,
[productprice] = @ProductPrice,
[productqty] = @ProductQty
WHERE [productid] = @ProductId ">
</asp:SqlDataSource>