6
Answers

How to get CheckedListBox values from DataBase?

Photo of Mayank Jani

Mayank Jani

7y
210
1
Dear All,
Greetings of the day..
 
Please take a look at my problem. I want to get the CheckedListBox items Checked according to the database when I select an option from a DataGridView.
 
In a WinForm, I have a DataGridView contains User names (XYZ, ABC etc.) and a CheckedListBox contains different rights (Billing, Purchase, Stores, Edit, Delete etc.) to the user. a user (e.g. XYZ) rights saved (e.g. Purchase, Billing etc.) to MS Access database in a table...
UserName   UserRights
XYZ              Billing
XYZ              Purchase
XYZ              EditBills
 
Now, i want to see all the rights given to XYZ in the CheckedListBox when I select name XYZ from the DataGridView.
 
I got almost result but there is something missing that compares the db to CheckedListBox.
Please see the screen shots attached to get it more clearly. in this code (The Code.jpg) I only get first few items checked regardless, the actual rights.
 
Thank You.
 
Mayank Jani

Attachment: TheCode.zip

Answers (6)

0
Photo of Dharmraj Thakur
NA 4.1k 61.7k 7y
Do not execute this query directly first understand all statements and thing about your requirement... here is basic queries, let me know next queries later after understanding this...
  1. --get current stock of product  
  2. Select ProductID, ProductName, ClosingStockQTy, ClosingStockRs from ProductMaster where Product = 1  
  3.   
  4. --on purchase add stock  
  5. insert into Purchases (BillNo, BillDate, ProductID, Rate, Discount, Qty, TotalAmount)  
  6. values  
  7. (  
  8.     'CP1',  
  9.     getdate(),  
  10.     @ProductID,  
  11.     @Rate,  
  12.     @Discount,  
  13.     @Qty,  
  14.     @TotalAmount  
  15. )  
  16.   
  17. declare @StockQTy as int=0;  
  18. set @StockQTy = (select top 1 ClosingStockQty from ProductMaster where ProductID = 1);  
  19. set @StockQTy = @StockQTy + @Qty;  
  20.   
  21. Update ProductMaster  
  22. set  
  23.     ClosingStockQTy = @StockQTy  
  24. Where  
  25.     ProductID = 1  
  26.   
  27.   
  28. --on sale decrease stock  
  29. insert into Sales (BillNo, BillDate, ProductID, Rate, Discount, Qty, TotalAmount)  
  30. values  
  31. (  
  32.     'CS1',  
  33.     getdate(),  
  34.     @ProductID,  
  35.     @Rate,  
  36.     @Discount,  
  37.     @Qty,  
  38.     @TotalAmount  
  39. )  
  40.   
  41. declare @StockQTy as int=0;  
  42. set @StockQTy = (select top 1 ClosingStockQty from ProductMaster where ProductID = 1);  
  43. set @StockQTy = @StockQTy - @Qty;  
  44.   
  45. Update ProductMaster  
  46. set  
  47.     ClosingStockQTy = @StockQTy  
  48. Where  
  49.     ProductID = 1
0
Photo of Ramesh Barik
NA 639 90 7y
You can use inner join and left join to get the result.
  1. select PM.ProductID, PM.ProductName, PM.MRP,  
  2. Purchase.BillDate as PurchaseBillDate,Purchase.Rate as PurchaseRate,  
  3. Sales.BillDate as SalesBillDate,Sales.Rate as SalesRate  
  4. from Productmaster PM  
  5. inner join Purchase on PM.ProductID=Purchase.ProductID  
  6. left join Sales on PM.ProductID = Sales.ProductID  
  7. where PM.ProductID= 1000