当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - GridView removes a row

问题描述:

I have my <asp:GridView ID="gridView" runat="server"> I bind it like this :

 myConnection.Open();

SqlCommand myCommand = myConnection.CreateCommand();

myCommand.CommandType = CommandType.StoredProcedure;

myCommand.CommandText = "sp_SelectWeek";

myCommand.Parameters.AddWithValue("@Division", Convert.ToInt32(e.PostBackValue));

SqlDataReader myReader = myCommand.ExecuteReader();

myReader.Read();

gridView.DataSource = myReader;

gridView.DataBind();

myReader.Close();

myConnection.Close();`

but when I run it It takes off one rowfrom the query. I'm sure of this because I tried it with a table and all the rows where there. I build a chart from the same query and you clearly see that I have one row missing :

What am I doing wrong ?

网友答案:

You're calling

myReader.Read();

before you pass the reader as a data source. So you moved the record pointer effectively. Thereby losing your one row. Just don't call Read and you should be good.

分享给朋友:
您可能感兴趣的文章:
随机阅读: