Class 'System.Data.SqlClient.SqlDataAdapter' cannot be indexed because it has no default property.

B

Bob of the West

Hi,
I'm trying to something quite straightforward, populate a datagrid
with certain fields after selecting from a dropdownlist. The books I
have don't seem to give an example of how to do this ( particularly
from within VStudio 2003 ) and it's driving me to distraction.

daNumber1 selects the au_id and au_lname
SqlDataAdapter1 is attempting to take the parameter @au_id to populate
the datagrid1, but the SqlDataAdapter1 is giving the error "Class
'System.Data.SqlClient.SqlDataAdapter' cannot be indexed because it
has no default property." I don't understand what the default ought to
be...

As I say, I have no book examples to work from, so I'm just cobbling
together other bits in an attempt to understand/get it to work -
apologies if my poor code offends thee!

Thanks,
bob

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SqlConnection1.Open()
daNumber1.Fill(dsNumber1)
If Not Page.IsPostBack Then
lstCategory.DataSource = dsNumber1()
lstCategory.DataValueField = "au_id"
lstCategory.DataTextField = "au_lname"
lstCategory.DataBind()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
DataGrid1.DataSource =
SqlDataAdapter1(lstCategory.SelectedValue)
DataGrid1.DataBind()
End Sub
 
W

William F. Robertson, Jr.

In your button click perhaps try this:

DataGrid1.DataSource = dsNumber1.Tables[0].Select( "au_id = " +
lstCategory.SelectedValue );
DataGrid1.DataBind();

Now this is dependent on the dsNumber1 being defined globally to the page.
Also, I am assuming dsNumber1 is a DataSet with the first table (zero based
indexes or indii ) having the DataGrid information.

bill
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top