Simple ".Fill" method not working...

aar0n

Member
Joined
Jan 17, 2008
Messages
19
Location
40 Miles S. of Nashville, TN
Programming Experience
5-10
Hi,

I'm new here. I'm not new to programming, but I am fairly new to .NET development. I'm learning .NET on the job and taking MS courses. I hope I'm posting this in the right place.

My attempts at creating a simple dataset using the data adapter's .Fill method is failing, as I'm getting "Invalid Object Name" although my table "SUBDIVISIONS" does exist (in my "PROPERTIES" SQL Server database).

Here is the code I'm having the problem with. I have verified my connection string, so my issue must be somewhere else. I must be missing something small but vital.

Any help would be greatly appreciated....here's the code....

VB.NET:
Public Class Form1
    Dim conn As New SqlClient.SqlConnection("Data Source=AARON;Initial Catalog=Properties;Integrated Security=True")
    Dim da As New SqlClient.SqlDataAdapter("SELECT * FROM SUBDIVISIONS", conn)
    Dim DS As New DataSet


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        da.Fill(DS, "SUBDIVISIONS")  'ERROR OCCURS HERE

    End Sub
End Class
 
Last edited by a moderator:
If you are using VS2005, I suggest (as others will) you use the built in GUI to design and create your dataTables, connection info and everything else, as it removes errors such as these, which occur when people try to code everything themselves.

At a random guess, it maybe because you haven't created the "SubDivisons" dataTable before you are trying to get data to fill into it...
 
If you are using VS2005, I suggest (as others will) you use the built in GUI to design and create your dataTables, connection info and everything else, as it removes errors such as these, which occur when people try to code everything themselves.

At a random guess, it maybe because you haven't created the "SubDivisons" dataTable before you are trying to get data to fill into it...


...yes, I am using VS2005.

The datatable I was referring to, "SubDivisions", is an existing datatable, so I'm not sure why it's not being recognized.

I'll take your advise and use the GUI to create my connection info...perhaps that will help. Thanks.
 
Turns out I had SQL Server pointing to the wrong database Owner...meaning it was something other than .dbo.

Database issue...not a code issue.

Anyway, glad to be here.

BTW,
Moderators...I'll know in the future to use the "code box" in future posts. :)
 
I'd use the GUI to do the whole lot:

Add a new DataSet to your project
Right click the surface
Add.. Query
Wizard appears, follow it to connect your db, select table, finish
Switch to form view
Show the Data Sources window (Data menu in VS i think)
Drag the node representing your table, onto the form

-> 30 seconds, and it's all working

For more info, read the DW2 link in my signature, start with the section Creating a Simple Data App
 
Back
Top