C
C#2y ago
bLanco

❔ This code is bugged how can i solve it?

LogiwaEntities1 db = new LogiwaEntities1();
ProductData productData = new ProductData();
productData.ProductName = txtProductName.Text;
string productName = productData.ProductName;
var x = db.tblProduct.Where(p => p.PRODUCTNAME == productName)
.Select(p => p.PRODUCTID)
.FirstOrDefault();
label3.Text = Convert.ToString(x);
db.tblProduct.Remove(x);
LogiwaEntities1 db = new LogiwaEntities1();
ProductData productData = new ProductData();
productData.ProductName = txtProductName.Text;
string productName = productData.ProductName;
var x = db.tblProduct.Where(p => p.PRODUCTNAME == productName)
.Select(p => p.PRODUCTID)
.FirstOrDefault();
label3.Text = Convert.ToString(x);
db.tblProduct.Remove(x);
22 Replies
bLanco
bLancoOP2y ago
the bug is i can't remove any data from database db.tblProduct.Remove(x);
x0rld
x0rld2y ago
you don't call SaveChanges ? 🤔
bLanco
bLancoOP2y ago
nope bro it's throw exception in debug
x0rld
x0rld2y ago
what's the exception ? 🤔
bLanco
bLancoOP2y ago
wait a sec first we have 1 more exception Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'int' to 'Logiwa.ProductManagement.tblProduct' Logiwa.ProductManagement
x0rld
x0rld2y ago
on which line ?
bLanco
bLancoOP2y ago
db.tblproduct.remove(x); LogiwaEntities1 db = new LogiwaEntities1(); ProductData productData = new ProductData(); productData.ProductName = txtProductName.Text; string productName = productData.ProductName; var x = db.tblProduct.Where(p => p.PRODUCTNAME == productName) .Select(p => p.PRODUCTID) .FirstOrDefault(); label3.Text = Convert.ToString(x); it's working but i can't remove X from database i can see ID on label
x0rld
x0rld2y ago
looks like ProducManagement things is not valid what's type is tblProduct ?
bLanco
bLancoOP2y ago
what
x0rld
x0rld2y ago
cannot convert from 'int' to 'Logiwa.ProductManagement.tblProduct
bLanco
bLancoOP2y ago
sometimes my english is not enough ooh
x0rld
x0rld2y ago
tblProduct is not supposed to have an int
bLanco
bLancoOP2y ago
yeah it's a datatable
bLanco
bLancoOP2y ago
GitHub
GitHub - polymorphism69/Logiwa.ProductManagement
Contribute to polymorphism69/Logiwa.ProductManagement development by creating an account on GitHub.
bLanco
bLancoOP2y ago
the code has a lot of bug it's not done this code from ProductManagement.cs if you want to view the codes
x0rld
x0rld2y ago
remove take an entity not an id for some reason and x is an int you are selecting only the ID var x = db.tblProduct.Where(p => p.PRODUCTNAME == productName) .Select(p => p.PRODUCTID) .FirstOrDefault();
bLanco
bLancoOP2y ago
they want do everything with using ID not product name, we don't want to use product name
x0rld
x0rld2y ago
try to remove the Select and see if it works
bLanco
bLancoOP2y ago
i've solved it
LogiwaEntities1 db = new LogiwaEntities1();
ProductData productData = new ProductData();
productData.ProductName = txtProductName.Text;
string productName = productData.ProductName;
var x = db.tblProduct.Where(p => p.PRODUCTNAME == productName)
.Select(p => p.PRODUCTID)
.FirstOrDefault();
label3.Text = Convert.ToString(x);
var y = db.tblProduct.Find(x);
db.tblProduct.Remove(y);
db.SaveChanges();
label3.Show();
MessageBox.Show("Product removed!", "Info",MessageBoxButtons.OK,MessageBoxIcon.Information);
LogiwaEntities1 db = new LogiwaEntities1();
ProductData productData = new ProductData();
productData.ProductName = txtProductName.Text;
string productName = productData.ProductName;
var x = db.tblProduct.Where(p => p.PRODUCTNAME == productName)
.Select(p => p.PRODUCTID)
.FirstOrDefault();
label3.Text = Convert.ToString(x);
var y = db.tblProduct.Find(x);
db.tblProduct.Remove(y);
db.SaveChanges();
label3.Show();
MessageBox.Show("Product removed!", "Info",MessageBoxButtons.OK,MessageBoxIcon.Information);
x0rld
x0rld2y ago
i'm almost sure if you do that it works
var x = db.tblProduct.Where(p => p.PRODUCTNAME == productName).FirstOrDefault();
db.tblProduct(x);
var x = db.tblProduct.Where(p => p.PRODUCTNAME == productName).FirstOrDefault();
db.tblProduct(x);
@UmutAtomic
bLanco
bLancoOP2y ago
i used this way to solve it @x0rld
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?