For simplicity, I have a database with two tables, as follows:
On my form, I'm trying to display information about a grade. I'm using a DataSet with BindingSources and TableAdapters. Using the tip from here, I'm populating the selected grade's ID, HazardType_ID and Code. Unfortunately, I want to display the the HazardType, and not the foreign key index. I've accomplished this with the following code:Code:/---------------------------------------\ | Table Name: GRADES | |---------------+---------+-------------| | Column | Type | Comments | |---------------|---------|-------------| | ID | Integer | Primary Key | | HazardType_ID | Integer | Foreign Key | | Code | Text | | \---------------+---------+-------------/ /------------------------------------\ | Table Name: HAZARDTYPES | |------------+---------+-------------| | Column | Type | Comments | |------------|---------|-------------| | ID | Integer | Primary Key | | HazardType | Text | | \------------+---------+-------------/
Is there an easier way of doing this? I'm very new to data driven programs, and I feel like I'm missing something very easy that will revolutionize my understanding.Code:' get the data Dim data As ProjectDataSet.GradesRow = DirectCast(GradesBindingSource.Current, DataRowView).Row ' fill in form fields With data lblTypeVal.Text = DirectCast(DirectCast(HazardTypesBindingSource.Item(HazardTypesBindingSource.Find("ID", .HazardType_ID)), DataRowView).Row, ProjectDataSet.HazardTypesRow).HazardType txtCode.Text = .Code End With
Note, I'm using VB Express 2008 (.NET 3.5) and connecting to a MS Access database.
Thanks.




Reply With Quote