|
-
Apr 27th, 2013, 04:56 PM
#1
Thread Starter
Banned
Populate new form based on Combobox
I am trying to learn VB 2010. I have an Starting form with a combobox that has the following code.
Code:
Public Class frmStartScreen
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSoftware.Click
frmAddSoftware.Show()
Me.Close()
End Sub
Private Sub frmStartScreen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Data_dbDataSet.tblSoftware' table. You can move, or remove it, as needed.
Me.TblSoftwareTableAdapter.Fill(Me.Data_dbDataSet.tblSoftware)
End Sub
Private Sub cboChooseSoftware_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboChooseSoftware.SelectedIndexChanged
Me.Validate()
Me.TblSoftwareBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Data_dbDataSet)
End Sub
Private Sub btnGoToSoftware_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoToSoftware.Click
End Sub
End Class
When "btnGoToSoftware" is click I want the next form to open with labels populated based on the selection. As of now i have 4 fields. idsSoftwareID, chrSoftwareName, dtmSoftwarePurchaseDate, chrSoftwareCompany in a table.
I am using chrSoftwareName to populate the Combobox. When the go button is clicked I want to open a new form with labels populated based on the chrSoftwareName in the combobox.
Thank You
Rab
-
Apr 28th, 2013, 01:33 AM
#2
Re: Populate new form based on Combobox
Hello,
Before getting into code and fields I would suggest explaining exactly what you want beginning with what information is being displayed on the first screen as the code shown is generic in nature expect for the word "Software".
Also I would highly suggest reconsidering names of fields in your table, each one of your fields currently has the word software in it, this is not needed, instead your table name would describe what the table is for, in this case "Software". With that said idsSoftwareID would become either ID or Identifier, chrSoftwareName would be Name or Product etc. dtmSoftwarePurchaseDate would be PurchaseDate. So a SELECT statement would be
Code:
SELECT ID, Product, PurchaseDate FROM Software
What if we add in a category? We can alias each column by table name i.e.
Code:
SELECT
Software.Product,
Categories.CategoryName,
Software.PurchaseDate
FROM
Categories
INNER JOIN
Software ON Categories.CategoryID = Software.CategoryID
OR
Code:
SELECT
Product,
CategoryName,
PurchaseDate
FROM
Categories
INNER JOIN
Software ON Categories.CategoryID = Software.CategoryID
So if you wanted to get used categories we would use
Code:
SELECT DISTINCT
Categories.CategoryName,
Software.CategoryID
FROM
Categories
INNER JOIN Software ON
Categories.CategoryID = Software.CategoryID
WHERE
Categories.CategoryID = Software.CategoryID
What I am trying to say is first get your requirements down on paper (or software such as Visio) then build your database with meaningful names and relationships. When you hit a barrier come back and explain in plain English what the problem is. Again as stated above, showing the code shown does no good as it is simply generic in nature.
Here is a good resource for coding
http://msdn.microsoft.com/en-us/library/fxsa23t6.aspx
For modeling databases
http://www.databaseanswers.org/data_models/index.htm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|