We help IT Professionals succeed at work.
Get Started

DataSets not getting info from dif tables

342 Views
Last Modified: 2012-07-07
I know my SQL statement is right and retunrs the right information I want. My problem lies somewhere with my VB code. My problem lies with a dataset not being able to grab information from other tables example
txtClientId.Text = ds.Tables("Firstdb").Rows(inc).Item("Clients.FirstName")
txtTechId.Text = ds.Tables("Firstdb").Rows(inc).Item("Techs.FirstName")
should return the clients firstname and techs firstname, but all it returns is blank info.
If i remove the table Clients. and just leave FirstName it returns the firstname but only for the clients firstname. If i comment out those 2 lines everything else though fills out with the correct information I want.

Public Class frmSecond
    'connection string to SQL database'
    Dim con As SqlClient.SqlConnection
    'adapter for SQL to fill ???'
    Dim da As SqlClient.SqlDataAdapter
    'new object dataset so we can grab the information from the database to store here?'
    Dim ds As New DataSet
    'just a public variable for a SQL statement'
    Dim SQL As String
    'variable to say what the last row is.'
    Dim MaxRows As Integer
    'Counts when navigating forwards and backwards for your database rows.'
    Dim inc As Integer

    Private Sub frmSecond_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        'connection() is grabbed from dbDataConnection to create a connection to SQL DB'
        con = connection()

        'SQL statement for Invoices connecting other tables for information'
        SQL = "SELECT Organizations.OrgName, Clients.FirstName, Techs.FirstName, Invoices.Date, Invoices.Notes, Invoices.Parts, Invoices.Labor, Invoices.Mileage, Invoices.TotalCost, Invoices.InvoiceNumber FROM Invoices Inner Join Organizations On Invoices.OrgId = Organizations.OrgId INNER JOIN Clients on Invoices.ClientId = Clients.ClientId INNER JOIN  Techs on Invoices.TechId = Techs.TechId"
        da = New SqlClient.SqlDataAdapter(Sql, con)
        da.Fill(ds, "Firstdb")

        MaxRows = ds.Tables("Firstdb").Rows.Count
        inc = -1
    End Sub
    Private Sub NavigateRecords()

        Try
            txtOrgId.Text = ds.Tables("Firstdb").Rows(inc).Item("OrgName")
 (Problem)  txtClientId.Text = ds.Tables("Firstdb").Rows(inc).Item("Clients.FirstName")
 (Problem)  txtTechId.Text = ds.Tables("Firstdb").Rows(inc).Item("Techs.FirstName")
            txtDate.Text = ds.Tables("Firstdb").Rows(inc).Item("Date")
            txtNotes.Text = ds.Tables("Firstdb").Rows(inc).Item("Notes")
            txtParts.Text = ds.Tables("Firstdb").Rows(inc).Item("Parts")
            txtLabor.Text = ds.Tables("Firstdb").Rows(inc).Item("Labor")
            txtMileage.Text = ds.Tables("Firstdb").Rows(inc).Item("Mileage")
            txtTotalCost.Text = ds.Tables("Firstdb").Rows(inc).Item("TotalCost")
            txtInvoiceNumber.Text = ds.Tables("Firstdb").Rows(inc).Item("InvoiceNumber")
        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
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