This is done in visual basic langauge. I created a
query and i want to invoke this query from code.
for example, if i select the Company-owned radio button and hit the
display button ONLY the information for company owned stores should
be shown. same for the other radio button except it will only show
the information for the Franchise ownership.
F. for Franchises
C. for company owned
please provide the appropriate code.
and select statements.
The very first thing is to create the sql query using the query builder for the condition that has been mentioned i.e. what radio button option has been selected before clicking on the display button. We need to pass a parameter to the query that will determine the result set, ,meaning if we want to show only company owned stores then we need to pass the parameter that will filter out the records. The parameter is defined in the where clause with '@' symbol as mentioned below.
SQL QUERY
SELECT Store, City, State, Sales, Ownership
FROM Stores
WHERE Ownership = @Ownership OR @Ownership IS NULL
@Ownership is the parameter that we need to pass to the query to get the desired result set. If we want only company owned stores, @Ownership should be set to 'C'. If we want Franchise owned stores , @Ownership should be set to 'F'. In case we need all records @Ownership should be NULL or Blank.
We can even use LIKE statement instead of '=' when a similar match is expected instead of exact. In that case query would be :
SELECT Store, City, State, Sales, Ownership FROM Stores
WHERE (Ownership LIKE @Ownership +'%' )OR (@Ownership IS NULL)
As shown in the picture before the FillyBy method could be recreated with the SQL Query mentioned above and rename the method as FillByOwnership.
Next step would be to write the code lines that will trigger the query and fill the data adapter accordingly.
So here we need to modify the code in the display button click event handler method as below :
====================VB code =================================================
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Try
If radAll.Checked Then 'when radio button All
is checked
StoresTableAdapter.Fill(AdaleneDataSet.Stores)
ElseIf radCompany.Checked Then 'when
radio button Company Owned is checked
StoresTableAdapter.FillByOwnership(AdaleneDataSet.Stores ,
'C')
Else 'when radio button Franchises is checked
StoresTableAdapter.FillByOwnership(AdaleneDataSet.Stores
, 'F')
End If
Catch Ex As Exception
MsgBox(Ex.Message)
End Try
End Sub
==========================================End=====================================
The above code would provide an idea how to solve the stated problem.
This is done in visual basic langauge. I created a query and i want to invoke this query from code. for example, if i select the Company-owned radio button and hit the display button ONLY the informat...
Zander Inc. stores employee IDs and salaries in a sequential access file named Employees.txt. Open the VB2015\Chap10\Zander Solution\Zander Solution (Zander Solution.sln) file. Open the Employees.txt file, which is contained in the project’s bin\Debug folder. The ID and salary information appear on separate lines in the file. Close the Employees.txt window. a. Define a structure named Employee. The structure should contain two member variables: a String variable to store the ID and a Double variable to store the salary. b. Declare...
Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb Public Class frmNewItem Public InvItem As InvItem Private Sub frmNewItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.LoadComboBox() End Sub Private Sub LoadComboBox() cboSizeOrManufacturer.Items.Clear() If rdoPlant.Checked Then cboSizeOrManufacturer.Items.Add("1 gallon") cboSizeOrManufacturer.Items.Add("5 gallon") cboSizeOrManufacturer.Items.Add("15 gallon") cboSizeOrManufacturer.Items.Add("24-inch box") cboSizeOrManufacturer.Items.Add("36-inch box") Else cboSizeOrManufacturer.Items.Add("Bayer") cboSizeOrManufacturer.Items.Add("Jobe's") cboSizeOrManufacturer.Items.Add("Ortho") cboSizeOrManufacturer.Items.Add("Roundup") cboSizeOrManufacturer.Items.Add("Scotts") End If End Sub Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click If IsValidData() Then InvItem = New InvItem(CInt(txtItemNo.Text),...