Very Basic DataGrid Help Needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jm

    Very Basic DataGrid Help Needed

    I manually put a datagrid in on a form. I then added this code to an
    event to populate it:

    OdbcConnection conn = new OdbcConnection( "DSN=CardBase") ;
    sqlCardHolders = "SELECT * FROM tblcardholders " +
    "WHERE last_name LIKE '%" + txtLastName.Tex t + "%'";
    DataSet rs = new DataSet();
    conn.Open();
    OdbcDataAdapter myOdbcAdapter = new
    OdbcDataAdapter (sqlCardHolders , conn);
    myOdbcAdapter.F ill(rs);
    dgridSearchResu lts.DataSource = rs;
    dgridSearchResu lts.SetDataBind ing(rs,"CardHol ders");

    I do not see anything in the datagrid except a little box with a plus
    and I can eventually expand it to show the row and it lets me edit it,
    etc.

    If I turn off Row Headers Visible, I don't even see the little plus.

    I just want to query the database and have the rows show up. I don't
    want to edit them or anything. I just can't find anything that shows
    me some basic tutorial on this. Thank you for any help.
  • Patrick Altman

    #2
    Re: Very Basic DataGrid Help Needed

    jm,

    The DataGrid is doing that because you are assigning it a DataSet as a
    DataSource. A DataSet contains a collection of Tables and possibly
    Relationships between those tables. If you want to only represent the
    DataTable in the collection represented by your single query, you'll need to
    specify the DataSource as being the DefaultView of the table you want to
    show.

    For example:
    dgridSearchResu lts.DataSource = rs.Tables[0].DefaultView;

    Hope that helps,

    Patrick Altman



    "jm" <john_20_28_200 0@yahoo.com> wrote in message
    news:c67e4bdd.0 408201222.3b894 866@posting.goo gle.com...[color=blue]
    > I manually put a datagrid in on a form. I then added this code to an
    > event to populate it:
    >
    > OdbcConnection conn = new OdbcConnection( "DSN=CardBase") ;
    > sqlCardHolders = "SELECT * FROM tblcardholders " +
    > "WHERE last_name LIKE '%" + txtLastName.Tex t + "%'";
    > DataSet rs = new DataSet();
    > conn.Open();
    > OdbcDataAdapter myOdbcAdapter = new
    > OdbcDataAdapter (sqlCardHolders , conn);
    > myOdbcAdapter.F ill(rs);
    > dgridSearchResu lts.DataSource = rs;
    > dgridSearchResu lts.SetDataBind ing(rs,"CardHol ders");
    >
    > I do not see anything in the datagrid except a little box with a plus
    > and I can eventually expand it to show the row and it lets me edit it,
    > etc.
    >
    > If I turn off Row Headers Visible, I don't even see the little plus.
    >
    > I just want to query the database and have the rows show up. I don't
    > want to edit them or anything. I just can't find anything that shows
    > me some basic tutorial on this. Thank you for any help.[/color]


    Comment

    Working...