troubleshooting Question

DataSets not getting info from dif tables

Avatar of easyworks
easyworksFlag for United States of America asked on
Visual Basic.NETMicrosoft SQL Server 2008
3 Comments1 Solution343 ViewsLast Modified:
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()

            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

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros