c# - Unable to cast object of type 'System.Data.Linq.DataQuery`1[System.Int32]' to type 'System.IConvertible' -
I am trying to insert data into my database that has 2 tables
Products
(Product ID): 1
(IDNumber): 200900110
(Product Name): Pepsi
Order
(OrderId): 1 (Increase of Auto 1)
(Product ID): 1 < Br> (date): 1/1/2009
This code is:
var db = new product order (); Var idNum = db.Product in p.IDNumber == 200900110 Choose p.ProductID; Var order = new order (); Order.productID = Convert toInt32 (idNum); order. Date = date time.Now; Db.Order.InsertOnSubmit (Ntime); Db.SubmitChanges (); After I run it, I get an error like this:
Type 'object' System.Data.Linq.DataQuery` 1 [System. Int32] to type 'System.IConvertible'
your query:
D.ProductID
Select p.IDNumber == 200900110 p from db.Product does not return a result, but a list of results. In your case it will be a list containing a product ID, you should modify it:
(from db.Product to p from p.IDNumber == 200900110 p.ProductID). Single () If you run your code in the debugger and you define your code on idNum , you will see that it is a dataccharacter Example.
Comments
Post a Comment