Cant get a gridview to bind to my dataset

C

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 = "";
 
E

Eric

you must select the table to be shown.

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

rg,
Eric
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top