How to re-populate a Data Grid?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a vb .net program which fills a data grid upon form load from an
acccess database. This works great. Now, I have to add a combo box and use
it to alter the underlying sql statement and re-fill the data grid. I have
never done this before, but I created a new sql statement in strSql from the
combobox, update the data adapter, and try to fill the data grid. The
program halts on the Fill with no particular explanation or complaint that I
can determine. Something tells me that I have to do something else before
the Fill from the dataset. Any suggestions?

Thanks,

Michael


Private Sub cboContactPosition_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles cboContactPosition.SelectedIndexChanged

' Define and build the SQL statement for the data grid . . .


..
..
..
daXtreme.SelectCommand.CommandText = strSql.ToString

' Fill the data grid using the new Sql command. . .

Me.daXtreme.Fill(dsXtreme) ' Debug hangs here for some
reason.

End Sub
 
Michael - if you aren't getting new rows from the database, you may want to
just use one of the datatable/dataview methods to filter your data. However
if you're freezing, then you need to look at what's happening there. First
check your sql command and make sure it's valid. Next make sure it's
returning and filling the datatable properly (make sure you don't have any
try/catch blocks that just eat the exception). Check the table to make sure
that you aren't filling on top of existing values (if you refilled a table
with no primary key or constraints, then the values woudl be appended at the
end and it would appear to not have changed, b/c the rows are down at the
bottom - even though the datatable has been refilled. If none of those are
it, let me know and we'll take it from there.

Cheers,

Bill
 
I added a try/Catch. I get "No value given for one or more required
parameters" from the Fill. I searched MSDN but to no avail yet. I can not
tell if the complaint is about the actual SQL code which looks fine and has
no parameters or something else. I keep thinking that some additional method
has to be executed prior to executing the second Fill. I will keep digging
.. . .

Michael
 
Michael,

I am not sure of your combobox is inside or outside the datagrid.

Have a look at our website there is a lot about the datagrid.

http://www.vb-tips.com/default.aspx

I have a sample with a combobox outside the datagrid, however never placed
it because that it can be confusing.

If that is were you looking for than reply *here*

By the way, this questions are often done in the newsgroup
microsoft.public.dotnet.languages.vb

There is as well my fellow Ken active while he is that not here.
Probably have you more change on answers when using the VB.Net than here.

I hope this helps so far.

Cor
 
Back
Top