Cant get a gridview to bind to my dataset

Discussion in 'ASP .Net Web Controls' started by catronro@gmail.com, Dec 15, 2005.

  1. Guest

    ok i am trying to pull a dataset back from my database and then have
    the searchResultsGridView diplay them. As i step through it the dataset
    is being populated but never displayed by the grid view. Any ideas


    message.Text = "";
    SqlConnection cn = new SqlConnection();
    SqlDataAdapter da = new SqlDataAdapter();
    DataSet ds = new DataSet();
    String sql = "";


    cn.ConnectionString = "Data Source=example;Initial
    Catalog=KnowledgeBase;Persist Security Info=True;User
    ID=someone;Password=";
    sql = "SELECT KBID, Topic, AppliesTo, LastModified FROM KB
    WHERE Approved = '1' and IsPayrollExport = '1' and Topic LIKE
    '%@Topic2%' ORDER BY Topic";

    da.SelectCommand = new SqlCommand(sql, cn);
    da.SelectCommand.Parameters.Add("@Topic2",
    SqlDbType.VarChar).Value = txtBoxSearch.Text;
    da.Fill(ds);
    //if (ds.Tables[0].Rows.Count > 0)
    // {
    searchResultsGridView.DataSource = ds;
    searchResultsGridView.DataBind();
    //}
    // else
    // {
    // message.Text = "No Articles matching your criteria
    could be found. Please try your search agian.";
    // }
    // message.Text = "";
    , Dec 15, 2005
    #1
    1. Advertising

  2. Eric Guest

    you must select the table to be shown.

    searchResultsGridView.DataSource = ds.table("KB")

    rg,
    Eric


    <> schreef in bericht
    news:...
    > ok i am trying to pull a dataset back from my database and then have
    > the searchResultsGridView diplay them. As i step through it the dataset
    > is being populated but never displayed by the grid view. Any ideas
    >
    >
    > message.Text = "";
    > SqlConnection cn = new SqlConnection();
    > SqlDataAdapter da = new SqlDataAdapter();
    > DataSet ds = new DataSet();
    > String sql = "";
    >
    >
    > cn.ConnectionString = "Data Source=example;Initial
    > Catalog=KnowledgeBase;Persist Security Info=True;User
    > ID=someone;Password=";
    > sql = "SELECT KBID, Topic, AppliesTo, LastModified FROM KB
    > WHERE Approved = '1' and IsPayrollExport = '1' and Topic LIKE
    > '%@Topic2%' ORDER BY Topic";
    >
    > da.SelectCommand = new SqlCommand(sql, cn);
    > da.SelectCommand.Parameters.Add("@Topic2",
    > SqlDbType.VarChar).Value = txtBoxSearch.Text;
    > da.Fill(ds);
    > //if (ds.Tables[0].Rows.Count > 0)
    > // {
    > searchResultsGridView.DataSource = ds;
    > searchResultsGridView.DataBind();
    > //}
    > // else
    > // {
    > // message.Text = "No Articles matching your criteria
    > could be found. Please try your search agian.";
    > // }
    > // message.Text = "";
    >
    Eric, Dec 17, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gareth Stretch
    Replies:
    0
    Views:
    4,747
    Gareth Stretch
    Jun 26, 2003
  2. A Traveler

    Cant bind Repeater to Custom Collection

    A Traveler, Oct 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    7,472
    A Traveler
    Oct 19, 2004
  3. Nagaraj
    Replies:
    1
    Views:
    853
    Lionel B
    Mar 1, 2007
  4. Paul
    Replies:
    2
    Views:
    395
  5. A Traveler

    Cant bind Repeater to Custom Collection

    A Traveler, Oct 19, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    196
    A Traveler
    Oct 19, 2004
Loading...

Share This Page