Link to home
Start Free TrialLog in
Avatar of Daniel Booker
Daniel BookerFlag for United States of America

asked on

DataSets not getting info from dif tables

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

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daniel Booker


Your right that did resolve my problem.

I know there are many ways to code something, but is the "standard" way you would want to handle a dataset problem like this?
Dunno why I didn't think of this.