stillwillyboy
Technical User
I am trying to join three tables and pull some info. With the following code, I keep getting an Exception error stating Incorrect syntax near '.'. The exception error is pointing at the line: m_daDataAdapter.Fill(m_dtClients)
(Please note that there are proper line continuations in my code, but the formatting changes when copying and pasting.)
I have looked and looked and can't see the problem. Any help will be rewarded. Thanks, Bill.
(Please note that there are proper line continuations in my code, but the formatting changes when copying and pasting.)
I have looked and looked and can't see the problem. Any help will be rewarded. Thanks, Bill.
Code:
Public Class frmConnectToSQLTest
Private m_cnADONetConnection As New System.Data.SqlClient.SqlConnection()
Private m_daDataAdapter As SqlClient.SqlDataAdapter
Private m_cbCommandBuilder As SqlClient.SqlCommandBuilder
Private m_dtClients As New DataTable
Private m_rowPosition As Integer = 0
Private Sub frmConnectToSQLTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_cnADONetConnection.ConnectionString = _
"Data Source=B-7M2KXC45F9FT4\SQLEXPRESS;Initial Catalog=ClientPayroll;Trusted_Connection=yes;User Id=B-7M2KXC45F9FT4\administrator"
m_cnADONetConnection.Open()
m_daDataAdapter = New SqlClient.SqlDataAdapter("Select " & _
"tbl_ClntBasicInfo.ClientNumber, tbl_ClntBasicInfo.LastName, " & _
"tbl_ClntBasicInfo.FirstName, tbl_ClntBasicInfo.MiddleInitial, " & _
"tbl_ClntPayRates.Average, tbl_ClntPayRates.Fringe " & _
"tbl_ClntClientBranch.BranchNumber " & _
"FROM (tbl_ClntBasicInfo " & _
"Inner Join tbl_ClntPayRates " & _
"ON tbl_ClntBasicInfo.ClientNumber = tbl_ClntPayRates.ClientNumber )" & _
"INNER JOIN tbl_ClntClientBranch " & _
"ON tbl_ClntBasicInfo.ClientNumber = tbl_ClntClientBranch.ClientNumber", m_cnADONetConnection)
m_cbCommandBuilder = New SqlClient.SqlCommandBuilder(m_daDataAdapter)
m_daDataAdapter.Fill(m_dtClients)
Me.ShowCurrentRecord()
End Sub
Private Sub frmConnectToSQLTest_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
m_cnADONetConnection.Close()
m_cnADONetConnection.Dispose()
End Sub
Private Sub ShowCurrentRecord()
If m_dtClients.Rows.Count = 0 Then
txtClientNumber.text = ""
txtLastName.text = ""
txtFirstName.Text = ""
txtMiddleInitial.Text = ""
txtAverage.Text = ""
txtFringe.Text = ""
txtLocation.Text = ""
Exit Sub
End If
txtClientNumber.text = _
m_dtClients.Rows(m_rowPosition)("ClientNumber").ToString
txtLastName.Text = _
m_dtClients.Rows(m_rowPosition)("LastName").ToString
txtFirstName.Text = _
m_dtClients.Rows(m_rowPosition)("FirstName").ToString()
txtMiddleInitial.Text = _
m_dtClients.Rows(m_rowPosition)("MiddleInitial").ToString()
txtAverage.Text = _
m_dtClients.Rows(m_rowPosition)("Average").ToString()
txtFringe.Text = _
m_dtClients.Rows(m_rowPosition)("Fringe").ToString()
txtLocation.Text = _
m_dtClients.Rows(m_rowPosition)("BranchNumber").ToString()
End Sub
End Class