Reputation: 357
I am populating a DataGrid from a table of SQL Data. My stored procedure pulls back a list of Usernames with the field name "Username". I declare a DataGrid and only one column again "Username". I get the error "A field or property with the name was not found on the selected data source.". The columns are the same name "Username" so I cant understand why I would get this, anyone have an idea?
Thanks in advance for any help!
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds);
BoundColumn c1 = new BoundColumn();
c1.HeaderText = "Username";
c1.DataField = "Username";
dgUsers.Columns.Add(c1);
dgUsers.DataSource = ds.DefaultViewManager;
dgUsers.DataBind();
Upvotes: 0
Views: 10247
Reputation: 2934
You should set the AutoGenerateColumns property of dgUsers to true and temporarily not add c1 to dgUsers.Columns. Then, the datagrid will show all the columns from the DataSource as they are returned and you will be able to see what is going on.
Upvotes: 1