Newbie: problem with first row in datagrid

  • Thread starter Thread starter Branimir Giurov
  • Start date Start date
B

Branimir Giurov

Use ORDER BY in the select clause.
Or create a dataview and sort it, then assign it to the DataSource property
of the grid.

Cheers,
Branimir
 
IDE: Visual Studio 2003 .NET
OS: Xp Pro

SqlCommand cmd = sqlCon.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select OrderID from Orders";

SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.SelectCommand = cmd;
DataSet dsResult = new DataSet();

adapter.Fill(dsResult, "Orders");
DataGridTableStyle tsl = new DataGridTableStyle();
DataGridColumnStyle testCol = new DataGridTextBoxColumn();
testCol.MappingName = "OrderID";
testCol.HeaderText = "Hello world";
testCol.Width = 150;
tsl.MappingName = "Orders";

tsl.GridColumnStyles.Add(testCol);
dataGrid1.TableStyles.Add(tsl);
dataGrid1.DataSource = dsResult;
dataGrid1.DataMember = "Orders";


This script fills a datagrid with the OrderID in Orders in database
NorthWind. My problem is that the first row displayed is OrderID=10249, but
there are one Order with id = 10248, and it isn't displayed until I click on
columnheader and sort the datagrid


Why??


Jeff
 
are you sure it doesn't appear?
I suppose it does appear but not in the order you expected it to - which
is no surprise, since you haven't used neither ORDER BY in the SQL nor
the DataView.Sort property.
 
Back
Top