I get the error in the subject when trying to run the code below. I am new to vb.net and am trying to convert and access database to vb.net. I am trying to bind a form to this query. Any help will be greatly appreciated.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim CN As New SqlConnection
Dim CNstring As String = _
"DATA SOURCE = \\CTIDATA; INITIAL CATALOG = JOBS; " & _
"Integrated Security = True"
CNstring = InputBox( _
"Please enter a Connection String", _
"CONNECTION STRING", CNstring)
If CNstring.Trim = "" Then Exit Sub
Try
CN.Open()
If CN.State = ConnectionState.Open Then
MsgBox("Workstation " & CN.WorkstationID & _
" connected to database " & CN.Database & _
" on the " & CN.DataSource & " server")
End If
Catch ex As Exception
MsgBox( _
"FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR" & _
vbCrLf & ex.Message)
End Try
Dim CMD As New SqlCommand( _
"SELECT tblAccounting.PaymentTerms, tblAccounting.[FIELD PAYROLLS], tblAccounting.[TAX EXEMPT], tblAccounting.[TAX APPLIES], tblCustomer.*, tblEngineerCompany.*, " & _
"tblJobDetails.*, tblJobReqs.*, tblSubcontractDetails.*, tblDatesHours.* " & _
"FROM tblJobCustomerID INNER JOIN " & _
"tblCustomer ON tblJobCustomerID.CustomerID = tblCustomer.CustomerID INNER JOIN " & _
"tblJobDetails ON tblJobCustomerID.JobNoCus = tblJobDetails.JobNo INNER JOIN " & _
"tblDatesHours ON tblJobDetails.JobNo = tblDatesHours.JobNoDH INNER JOIN " & _
"tblAccounting ON tblJobDetails.JobNo = tblAccounting.JobNoAcct INNER JOIN " & _
"tblJobEngineerID ON tblJobDetails.JobNo = tblJobEngineerID.JobNoEng INNER JOIN " & _
"tblEngineerCompany ON tblJobEngineerID.EngineerCompanyID = tblEngineerCompany.EngineerCompanyID INNER JOIN " & _
"tblJobReqs ON tblJobDetails.JobNo = tblJobReqs.JobNoReq CROSS JOIN " & _
"tblSubcontractDetails ", CN)
Dim Count As Integer
CN.Open()
Count = CMD.ExecuteScalar
If CN.State = ConnectionState.Open Then CN.Close()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim CN As New SqlConnection
Dim CNstring As String = _
"DATA SOURCE = \\CTIDATA; INITIAL CATALOG = JOBS; " & _
"Integrated Security = True"
CNstring = InputBox( _
"Please enter a Connection String", _
"CONNECTION STRING", CNstring)
If CNstring.Trim = "" Then Exit Sub
Try
CN.Open()
If CN.State = ConnectionState.Open Then
MsgBox("Workstation " & CN.WorkstationID & _
" connected to database " & CN.Database & _
" on the " & CN.DataSource & " server")
End If
Catch ex As Exception
MsgBox( _
"FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR" & _
vbCrLf & ex.Message)
End Try
Dim CMD As New SqlCommand( _
"SELECT tblAccounting.PaymentTerms, tblAccounting.[FIELD PAYROLLS], tblAccounting.[TAX EXEMPT], tblAccounting.[TAX APPLIES], tblCustomer.*, tblEngineerCompany.*, " & _
"tblJobDetails.*, tblJobReqs.*, tblSubcontractDetails.*, tblDatesHours.* " & _
"FROM tblJobCustomerID INNER JOIN " & _
"tblCustomer ON tblJobCustomerID.CustomerID = tblCustomer.CustomerID INNER JOIN " & _
"tblJobDetails ON tblJobCustomerID.JobNoCus = tblJobDetails.JobNo INNER JOIN " & _
"tblDatesHours ON tblJobDetails.JobNo = tblDatesHours.JobNoDH INNER JOIN " & _
"tblAccounting ON tblJobDetails.JobNo = tblAccounting.JobNoAcct INNER JOIN " & _
"tblJobEngineerID ON tblJobDetails.JobNo = tblJobEngineerID.JobNoEng INNER JOIN " & _
"tblEngineerCompany ON tblJobEngineerID.EngineerCompanyID = tblEngineerCompany.EngineerCompanyID INNER JOIN " & _
"tblJobReqs ON tblJobDetails.JobNo = tblJobReqs.JobNoReq CROSS JOIN " & _
"tblSubcontractDetails ", CN)
Dim Count As Integer
CN.Open()
Count = CMD.ExecuteScalar
If CN.State = ConnectionState.Open Then CN.Close()