We help IT Professionals succeed at work.
Get Started

vb 2005 Data constraints

Marcusw asked
Last Modified: 2010-08-05
i am building an applications that i would like to have a form with a tabcontrol on it.

what i would like to do is put 2 tabs on on which tab1 is a form that contains company details
and on tab to it contains a form that contains all related contacts. (there may be multiple contact for each company so need to be able to move through them.)
then within tab2 i am adding another tab control with 2 tabs one that dispalys a grid of all quotes and 2 that displays a grid of all orders

i have found out how to build the commands and fill a dataset but i don't know how to relate these reecords so that when the company changes the contact automatically change to related contact and the quote and orders then update to show only releated records to the current contact

how do i do  this
my code so far is below

The data is actually all related in the sql database already if that makes any difference

Imports System.Data
Imports System.Data.SqlClient

Public Class Companies
    Public ds As New DataSet
    Private da As New SqlDataAdapter()
    Private da1 As New SqlDataAdapter()
    Private objCommand As New SqlCommand
    Private objCommand1 As New SqlCommand

    Public objDataView As DataView
    Public objDataView1 As DataView
    Public objCurrencyManager As CurrencyManager
    Public objCurrencyManager1 As CurrencyManager

    Private Sub Companies_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim objConnection As New SqlConnection(strConnection)

        objCommand.Connection = objConnection
        objCommand.CommandText = "sp_User_Companies"
        objCommand.CommandType = CommandType.StoredProcedure
        objCommand.Parameters.Add("@UserID", SqlDbType.Int, 2).Value = userID
        da.SelectCommand = objCommand

        objCommand1.Connection = objConnection
        objCommand1.CommandText = "sp_User_Contacts"
        objCommand1.CommandType = CommandType.StoredProcedure
        objCommand1.Parameters.Add("@userID", SqlDbType.Int, 2).Value = userID
        da1.SelectCommand = objCommand1

        ' Open the connection and execute the reader



    End Sub

    Private Sub FillDataSetAndView()
        da.Fill(ds, "companies")
        da1.Fill(ds, "contacts")
        ds.Relations.Add("PKID", ds.Tables.Item("companies").Columns("ID"), ds.Tables.Item("contacts").Columns("ID"), True)

        ' Set the DataView object to the DataSet object...
        objDataView = New DataView(ds.Tables("companies"))
        objDataView1 = New DataView(ds.Tables("contacts"))
        ' Set our CurrencyManager object to the DataView object...
        objCurrencyManager = CType(Me.BindingContext(objDataView), CurrencyManager)
        objCurrencyManager1 = CType(Me.BindingContext(objDataView1), CurrencyManager)

    End Sub

Watch Question
This problem has been solved!
Unlock 2 Answers and 18 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE