954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Data not showing up in DataGrid

Hi guys! Long time no see!

I'm trying to get a datagrid to work, but although when I run it there is no error, nothing appears on the datagrid. Yet, there seems nothing wrong with my code:

SQL = "select * from upload " & _
                      "where field003 like 'P'+'%'+'" & PONo & "' " & _
                      "and field009 like 'Being received' order by field003"

                'Set up connections
                Dim SQLCommand = New SqlCommand(SQL, conn)
                conn.Open()
                Dim da As SqlDataAdapter = New SqlDataAdapter(SQLCommand)
                Dim ds As New DataSet

                da.Fill(ds, SQL)

                'Attach dataset to datagrid
                dgBlowOut.DataSource = da


Thank you for your help:)

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

If you are using asp.net you need to use bind

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

Not using asp.net. I'm creating a small desktop application.

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

try setting the datamember
The dataset can have multiple tables, when you set the datasource you need to specify which table to use

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

Setting the datamember to the name of the table?

[code=VB.NET] dgBlowOut.DataMember = "upload"
[\code]

When I added that it gave me an error: 'Child list for field upload cannot be created'

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

The dataset table, not the sql table

Dim ds As New DataSet("uploads")

....

 dgBlowOut.DataMember = "uploads"
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

I have also realized that in trying to run this application, after a while this error appears:
"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this error may be caused by the fact that under the default settings SQL Server does not allow remote connections."

I had never seen this error before this time because when I clicked the View button and it did not change the datagrid, I would have closed it immediately..... it came up after about 4 seconds.

Does this help anyone to assist me?

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

the Dataset is using a raw SQL statement that is being stored in a string variable SQL -

SQL = "select field003 as 'PO #',field009 as 'Status' from upload " & _
                      "where field003 like 'P'+'%'+'" & PONo & "' " & _
                      "and field009 like 'Being received' order by field003"
.....


I don't understand what the dataset table is...

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

One more piece of info: Here's the connection string (As the issue seems to be a connection one.
[code=VB.NET]
Public Const ConnectionString = "Data Source=SBIDB2SVR;Initial Catalog=rbeacon;User Id=sbiapps;Password=sbiapps123;"
[\code]

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

As long as you are sure the the datasource is correct and you can 'ping' the server then you need to configure the sql server to allow tcp ip connections.

Here's some links to show you how
http://www.datamasker.com/SSE2005_SCM1.htm

http://www.datamasker.com/SSE2005_SAC.htm

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

ok, I'm a little confused as to why it is talking about SQL Server 2005 in the first place; I'm using SQL Server 2000.... I went looking around for where tcp ip connections are either enabled or disabled - and I found it, but it's already enabled for tcp ip!

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Hmmm. Something is up with that. Are you running SQL 2000 and SQL 2005 on that machine then?

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

The server is SQL 2000...I am using Visual Basic 2005 Express to code the application. That's the only 2005 thing on my PC.

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

I have changed the connection string username and password and the connection seems to now be working - but now I'm back to the original issue: I can't get the datagrid populated from records using the SQL SELECT statement.

SQL = "select field003 as 'PO #',field009 as 'Status' from upload " & _
                      "where field003 like 'P'+'%'+'" & PONo & "' " & _
                      "and field009 like 'Being received' order by field003"

   'Set up connections
   Dim SQLCommand = New SqlCommand(SQL, conn)
   conn.Open()
   Dim da As SqlDataAdapter = New SqlDataAdapter(SQLCommand)
   Dim ds As New DataSet

   da.Fill(ds, SQL)

   'Attach dataset to datagrid
   dgBlowOut.DataSource = da


When I run it and enter a valid PO number, no records are displayed, but I can see the records when I run the SQL locally using Query Analyzer on my machine.

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

remember the datamember

Dim ds As New DataSet("uploads")

....

 dgBlowOut.DataMember = "uploads"
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

Ok so now I'm trying to understand the Datamember... is the DataSet("Uploads") the NAME of a Dataset? As in that code creates a dataset with a name?

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Ok I have created a dataset name Uploads and set the datamember using the code given...

[code=VB.NET]
Dim ds As New DataSet("Uploads")
....
dgBlowOut.DataMember = "Uploads"
[\code]

and now I get this error

"Child list for field Uploads cannot be created."

Ok so now I'm trying to understand the Datamember... is the DataSet("Uploads") the NAME of a Dataset? As in that code creates a dataset with a name?
bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Yes, that is the name of dataset. The problem seems to be that it doesn't know what table to use.
The dataset 'can' have multiple tables, and the datagrid doesn't know what to get its records from.

Check out these links for more clarification.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagrid.datasource.aspx

http://msdn.microsoft.com/en-us/library/ms810286.aspx

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

You might be able to do it generically and set

dgBlowOut.DataMember = ds.Tables[0].TableName

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

You might be able to do it generically and set

dgBlowOut.DataMember = ds.Tables[0].TableName

When I tried that I got this error: value of type 'System.Data.DataTableConnection' cannot be converted to string.

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You