我想用datatable做个购物车,点击"购物"在datable中添加购物清单,但是我的“购物”按钮的onclick子程序:
public Sub Add(s As object,e As EventArgs) Dim drowProduct As DataRow Dim dtblProduct As DataTable dtblProduct = dstProduct.Tables("ShoppingCart") ##Object reference not set to an instance of an object.## drowProduct = dtblProduct.NewRow drowProduct("product_ID") = ProductID drowProduct("product_name") = ProductName drowProduct("product_price") = ProductPrice dstProduct.Tables("ShoppingCart").rows.add(drowProduct) UpdateShoppingCart() dgrdProduct.DataSource = dstProduct dgrdProduct.DataBind() End Sub 出现:Object reference not set to an instance of an object 我的page_Load如下:
dstProduct = New DataSet() conNewProduct = New SqlConnection("Server = localhost;Trusted_Connection = SSPI;Database = newproduct") dadProduct = New SqlDataAdapter("Select product_ID,product_name,product_price from product where product_ID = @ProductID",conNewProduct) dadProduct.Selectcommand.Parameters.Add("@ProductID",intProductID) dadProduct.MissingSchemaAction = MissingSchemaAction.AddWithKey cbProduct = New SqlCommandBuilder(dadProduct) dadProduct.Fill(dstProduct,"ShoppingCart") 'dtblProduct = dstProduct.Tables("ShoppingCart") dgrdProduct.DataSource = dstProduct dgrdProduct.DataBind() 请教!我被这个问题困了2个星期了,查资料,翻书,上面这两个子程序简直都是书上照瓢画葫芦~~~~还是不行。请诸位大哥大姐,看贴的老少爷们,帮帮我,我喊您大爷!!!