Datagrid and the big Red "X"

J

Jon Pope

I'm using VS.NET 2002 with VB.NET. I'm populating a datagrid with the
resultset of the following query:

strSQL = "SELECT *, ContactLastName + ', ' + ContactFirstname AS
ContactFullName " & _
"FROM Clients " & _
"ORDER BY CompanyName"

da = New SqlClient.SqlDataAdapter(strSQL, d)
ds = New DataSet()
da.Fill(ds, "Clients")
dgdClients.DataSource = ds.Tables("Clients")

I also use this same code fragment to refresh the datagrid (usually after a
time interval to insure the displayed data is current). Every so often, the
last line causes an error, and the error message claims there's no column
named "ContactFullName". Usually this occurs when I attempt to rebind the
datagrid to a new datatable as shown in the above code fragment.

Is there a "proper" way to rebind a datagrid to a new datatable? LIke I
said, this only happens occasionally.

Cheers, Jon
 
B

Brian Davis

Try using the SetDataBinding method instead of setting the DataSource
directly. I believe that setting the DataSource directly more than once can
cause problems with the DataGrid.


Brian Davis
www.knowdotnet.com
 
G

Guest

Hi Jon,

Have you tried Brian's suggestion to use SetDataBinding method? Is your
problem resolved?

If you still have any concern, please feel free to feedback, I will help
you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top