how to calculate the difference between the sum of each column from different datagridview and to show it in a datagridview - sql

Hello I am a student in computer science , we ve got a inventory system project to do.
I have a problem
using sql I know how to importe sql to datagridview. I know have to save data in sql database using vb
but I still don t know how to calculate the difference of sum of each column from each different datagridview and to show it in datagridview.
My gol is:
I have a datagridview1 that shows the quantity of purchsases of a product in column A.and I have another datagridview2 that shows the quantity of sells of the same product in column B.
Datagridview1 is on form1.vb.
datagridview is on form2.vb0
what I want is : to calculate and view the stock the stock still available on new form3.vb on datagridview3.
thanks in advance

You need to follow the following steps (For selected Row):
Dim Data1 As String = GridView1.SelectedRow.Cells(Column Number).Text
Dim Data2 As String = GridView2.SelectedRow.Cells(Column Number).Text
Data1 - Data2
Save the result in a new table (database)
Show the new gridview3
Repeat for all rows.

Related

SSRS Query result in one cell based on other cells in the same row

Have not yet had to do this in SSRS and I'm scratching my head.
Basically, I have a tablix based on DataSet 1. The tablix is sorted and grouped on a field called AssemblyName and it is also the first column value. The second column value is based on the sum of a field called Quantity. (in the database table, each row has an AssemblyName value and a Quantity value)
The tricky part is this: There is another table in the database that contains a 'snapshot' of the AssemblyName and Quantity based on older (original) data.
And in my Tablix I want to show a cell in the same row that Sums the old Quantities for the AssemblyName in the first cell of the row. The old Quantities would be pulled from the database table with the old data.
Basically, the goal is the show a Tablix grouped and sorted by AssemblyName, and have the following columns in the tablix: Assembly Name (from current DB table), the current Quantity sum (from current DB table), and the old Quantity sum (from another DB table with the old data).
I have everything working except for the cell that contains the old Quantity sum from the old DB table.
The old DB table is in the same database, so that is not an issue, what my problem is, creating a query that sums the Quantities in the old table based on the value of the AssemblyName in the same Tablix row.
I've tried creating Dataset 2 with a query based on parameters pulled from Dataset 1, and then writing this expression in the old quantity cell:
=Sum(Fields!Quantity.Value, "Dataset 2")
I'm getting blank values in every cell in the third column, which contains the expression above. I'm assuming it because the Dataset 2 is not actually reading the values of AssemblyName in the same tablix row. The essence of what I want to do, however, is pass the value from the first column in the tablix, which contains AssemblyName, to the WHERE clause in the query for Dataset 2 whose parameter is in turn shown in the third column's cell in the same tablix row.
In case it helps, the query from DataSet 2 is as follows:
SELECT AssemblyName
, Quantity
FROM OldData
WHERE AssemblyName = #compare_AssemblyName
I hope this makes sense, but please ask questions as needed so that I can clarify.
Regards.
You should be able to pull the old data in along with your new data in the same query, then just sum the respective fields:
SELECT AssemblyName
, NewQuantity = n.Quantity
, OldQuantity = COALESCE(o.Quantity, 0)
FROM NewData n
LEFT JOIN OldData o
ON n.AssemblyName = o.AssemblyName
WHERE n.AssemblyName = #compare_AssemblyName

Inputting Data into Database and reading it

I have an SQL database and 2 VB applications, teacher and student application.
In the teacher application, the SQL database is connected with datagridview. In the form there are 10-15 checkboxes. those checkboxes are a set of weak points the teacher can select for a student in their class. for eg- "weak in calculations" etc. I want, when the teacher select the checkboxes, they should be shown in the teacher application in a string form. I think assigning each check box an ID would be a lot better than inputting long strings into the database. when the teacher selects a checkbox, the ID for that checkbox goes into the datagridview selected cell. I am not sure how to seperate each ID in the same cell because the teacher can select multiple checkboxes.
I need help with seperating the IDs and then reading them.
http://www.filedropper.com/sample_18 here is a sample program i made, it shows entering the checkbox id into the datagridview.
Let's keep it simple. Let's say we have 3 check boxes.
So for saving to db:
dim totalValue as integer = 0
if (chkBox1.checked) then totalValue +=1
if (chkBox1.checked) then totalValue +=2
if (chkBox1.checked) then totalValue +=4
save to db the totalValue
For reading from db:
totalValue = get this value from db
chkBox1.checked = ((totalValue and 1)=1)
chkBox1.checked = ((totalValue and 2)=2)
chkBox1.checked = ((totalValue and 4)=4)

get previous total from filtered amount in crystal report

I have created the following report in Crystal Report using VB.Net 2012. The OPENING BALANCE & NET TOTAL rows are not in my report but my question is there.
TR_ID | TR_DATE |DETAILS | EXPENSE | INCOME | BALANCE
OPENING BALANCE 0.00
1005 08/24/2015 CASH RTN 0.00 10,000.00 10,000.00
1013 08/25/2015 PURCHASE 3,500.00 0.00 6,500.00
1014 08/25/2015 DEPOSIT 5,000.00 0.00 1,500.00
1013 08/27/2015 SALES 0.00 4,000.00 5,500.00
NET TOTAL 5,500.00
I filtered the specific records within the date range of 08/25/2015 and 08/26/2015 & it works well. My question is how I get the previous balance (10000) of the specific date (08/25/2015) in "OPENING BALANCE" row and the total balance in "NET TOTAL" row?
As per the given datas above, the report shows the 4 records well excluding the rows of OPENING BALANCE & NET TOTAL. I want to add the OPENING BALANCE row to show the opening balance of every vendors' accounts when I open the report. And if I view the records of a particular customer within a date range, then OPENING BALANCE row should show the previous balance until the start date of the given date criteria. Ex: If I select records from 08/25/2015 to 08/26/2015 as per above datas, the report will show the two particular records (2nd & 3rd). But I want to show the previous balance 10,000 or the total amount which is above to the star date (08/25/2015) should be shown in the OPENING BALANCE row. And the sub total amount of this vendor's
should be shown in the last NET TOTAL row. So, pls help me, how the formulas will come & how to do.
Thank you
I expect your great help
Thank you
It´s not too much clear to me, but you may try to get the values directly from the report using a variable to do it.
With the report opened, you may entry in the CrystalReport option and select "Selection Expert - Saved Data".
You must create a formula using the "Formula Field" at left panel, and build it using the top 3 windows:
The first top window shows the fields of the table your report handles;
The middle top window show some built-in formulas
SO, you must
Go to formula field and create a new one;
Select the field at the top-left window you want to get (the Openning)
Drag-drop it into the main window (below the 3 top selections) and save it as a new variable
Add this variable into your report. This way, you may get this field for calculations in the same report.
Is it you need to do?
Sorry if I cannot understand exactly what you need.
Hugs!
UPDATE
You may have TOTAL creating a formula of SUM within report.
Click on the field EXPENSE (which appear in 3 rows) and select in menu: CRYSTAL REPORTS - INSERT - SUMMARY. It will create a field that must be positioned at the bottom (in the new Group will be created).
Do the same with INCOME field.
Create a FORMULA FIELD at the bottom to calculate the difference between both SUMARIES. You can name each of these summary fields (like IncSum and ExpSum) and put in that third field: IncSum-ExpSum. You may also put them as invisible.
Your final balance should be:
OldBalance (the parameter I point next lines)
+
Movement (the field that reflects IncSum-ExpSum)
To get the last/old Balance, you may have to get it from code as pass it as a PARAMETER. To do this, create a parameter in te report: see in the FIELD EXPLORER you have a choice of PARAMETER FIELD. AFter create it, use this code:
Dim MyCrystalReportt As New ReportDocument()
MyCrystalReportt.Load(Application.StartupPath & "\ReportSample.rpt\")
MyCrystalReportt.SetDatabaseLogon(UserID, Password, DataSource, InitialCatalog)
Dim myLogonInfo As New TableLogOnInfo()
Dim myTable As Table
For Each myTable In MyCrystalReportt.Database.Tables
myLogonInfo = myTable.LogOnInfo
myLogonInfo.ConnectionInfo.ServerName = DataSource
myLogonInfo.ConnectionInfo.DatabaseName = InitialCatalog
myLogonInfo.ConnectionInfo.UserID = UserID
myLogonInfo.ConnectionInfo.Password = Password
myTable.ApplyLogOnInfo(myLogonInfo)
Next
MyCrystalReportt.SetParameterValue("Data1", LastBalance.Value.ToString)
ReportsForm.CrystalReportViewer1.Reportsource = MyCrystalReport
ReportsForm.show
Notes:
You may have a form (ReportsForm) with a Crystal Control within (CrystalReportViewer1).
Datasource is the Server Name or IP
InitialCatalog is the Database (not the table!)
The ParameterValue MUST be a string - is numeric is required, convert it to number inside the Report. Use a temp_field to get it (see formulas of Crystal and you will find some to make this task).
I hope it can help you.
Good luck.

vb if condition on items and price from database

I actually have a Access database where i have a table called "tblfreight" and two column is there (items and Price)
And I want to auto show the Price when I choose Items.
There is two Textbox: "txtitems" and "txtprice"
I want to be like this....
If txtitems.text = select from tblfreight and column items Then
txtprice.text = select from tblfreight and column Price
Else txtprice.text=0 (Zero)
You need to query your DB first..
Select * from tblfreight - will get you your data you need.
Then you need to put this data somewhere. You can use a combobox for this. Once you have your combobox filled with your data you then can set the price into a label or textbox easily.
You can use the combobox selected index changed event...
Inside the changed event something like this would work...
textprice.text = Combobox.selecteditem.value
This will give you a great start, that's why this answer just gives you the steps and not the full code.

one problem in fetching a data from backend in vb.net

i have two item in form it is---1 is textbox and 2nd is combo box.
now i have single value in textbox .
but there is a multiple value for a combobox with is totally depend on a value of textbox....
*i am already add data to the backend files ... in which 1 columns that is called column A it's value is for textbox and 2 column that is called column B it's value for combo box *
When i write in textbox it's dependent ALL value can be get in the combo box.
Can any one solve my problem... It is a row vice search.....
I used a Ms Access for my backend......
How i can create a table that can be i used for a my problem
Give me any reference or codes.
This is probably Category->Product kind of scenario, where ONE Category can have ONE or MORE Products,
Category "Softdrink" can have Products("Coke","Pepsi" etc.)
Category "Harddrink" can have Products("8 PM","BP",etc.)
So when u will put "Softdrink" in your textbox then you want to get the relevant products for it. (Assumed you are using TextChange event)
SQL - select Product.Name from Category Inner Join Product On Category.Id= Product.Category_Id where CategoryName ="Softdrink"
and table structure would be like,