0

I am new to programming and I am working on a project using SQL and VB in Visual Studio 2013. One of the errors that has me stumped is as follows:

Imports System.Data
Imports System.Data.SqlClient

This error occurs at the following line:

da.Fill(ds)

Under additional information the following message is included:

Additional information: Invalid object name 'Complaints'.

I do have a Form named "Complaints" What am I missing? Thanks for any help you can provide! Please find the code below:

Public Class DButil
    Public cs As String

    Public Function GetDataView(ByVal sql As String) As DataView
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(sql, cs)

        da.Fill(ds)

        Dim dv As New DataView(ds.Tables(0))
        Return dv
    End Function

    Public Sub New()
        Dim strPath As String = Replace(System.AppDomain.CurrentDomain.BaseDirectory, "bin\debug", "cms.mdf")
        cs = "Data Source=(LocalDB)\v11.0;"
        cs += "AttachDbFilename='C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf';Integrated Security=True"
        cs += "Integrated Security=True;Connect Timeout=30"
    End Sub

End Class
5
  • 1
    "I do have a form named "Complaints"" - ? It is referring to a Table called Complaints... Commented Dec 20, 2013 at 23:58
  • 1
    What's in the variable 'sql' ? Commented Dec 21, 2013 at 0:01
  • The problem is in the string passed as sql command for the DataAdapter. Show that string (sql) Commented Dec 21, 2013 at 0:05
  • Thanks for the replies, guys. Here is the code for the sql variable: Commented Dec 21, 2013 at 0:07
  • Private Sub LoadGrid() Dim sql As String sql = " SELECT Table.ComplaintID, Complaint.OpenDate, Status.StatusTitle, " sql += "Table.Location, Table.Description FROM Table " sql += " INNER JOIN Status ON Table.StatusID = Status.StatusID ORDER BY Table.OpenDate DESC" grdComplaints.DataSource = DB.GetDataView(sql) End Sub Commented Dec 21, 2013 at 0:07

1 Answer 1

2

From your comment

Private Sub LoadGrid() 
    Dim sql As String sql = "SELECT Table.ComplaintID, Complaint.OpenDate, Status.StatusTitle, " 
    sql += "Table.Location, Table.Description FROM Table " 
    sql += " INNER JOIN Status ON Table.StatusID = Status.StatusID ORDER BY Table.OpenDate DESC"
    grdComplaints.DataSource = DB.GetDataView(sql) 
End Sub 

You use a field named OpenDate from a table named Complaint, but this table is not listed in the JOIN clause of the sql statement. You need to specify this table in the JOIN clause (or remove the column from the SELECT columns list )

Given the actual field names probably you need to set the relationship between Table.OpenDate and Complaint.OpenDate

Dim sql As String sql = "SELECT Table.ComplaintID, Complaint.OpenDate, Status.StatusTitle, " 
sql += "Table.Location, Table.Description FROM Table " 
sql += "INNER JOIN Status ON Table.StatusID = Status.StatusID "
sql += "INNER JOIN Complaint ON Table.OpenDate = Complaint.OpenDate " 
sql += "ORDER BY Table.OpenDate DESC"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.