Home All Groups Group Topic Archive Search About

Cant get a gridview to bind to my dataset

Author
15 Dec 2005 9:50 PM
catronro
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 = "";

Author
17 Dec 2005 12:51 AM
Eric
you must select the table to be shown.

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

rg,
Eric


<catro***@gmail.com> schreef in bericht
Show quoteHide quote
news:1134683421.534910.320530@z14g2000cwz.googlegroups.com...
> 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 = "";
>