Hi there,
I have a c# winform app.
I'm using Dapper to insert a bunch of data to database table called tbProducts
when it insert I get duplicated rows of an insertion. I pass ProductModel class to db.InsertNewProductModel method. I uploaded my code.
Anyhelp is appreciated
Phothong DungpasearchPosted Mar 25, 2021, 7:47 AM
Suraj DubeyPosted Mar 25, 2021, 6:23 AM
-the simple logic is you have to first find using query that. is there any same record exist in database if record is exist then do not insert the new record in the database, otherwise the insert the record in the database.
Note:- by using for each loop you can achive your requirement
sample of code
String name = edtName.getText().toString().trim(); String query = "Select * From STUDENTS where name = '"+name+"'";if(sqLiteHelper.getData(query).getCount()>0) { Toast.makeText(getApplicationContext(), "Already Exist!", Toast.LENGTH_SHORT).show();}else{ sqLiteHelper.insertData(name,edtPrice.getText().toString().trim(),imageViewToByte(imageView)); Toast.makeText(getApplicationContext(), "Added successfully!", Toast.LENGTH_SHORT).show(); }