user1442828
user1442828

Reputation: 23

ASP.net Gridview does not display first row

SqlDataReader myReader1 = null;
SqlCommand myCommand1 = new SqlCommand("SELECT Standard_Note_Code,     COUNT(Standard_Note_Code) as Count FROM [Excel_table] where Standard_Note_Creator_Name =  '" + ddlrep.Text + "' and (Std_Note_Date_Entered >= '" + datefrom + "' and Std_Note_Date_Entered <= '" + dateto + "') group by Standard_Note_Code", myConnection);

myReader1 = myCommand1.ExecuteReader();
myReader1.Read();

gvsummary.Visible = true;
if (myReader1.HasRows)
{                    
    gvsummary.DataSource = myReader1;
    gvsummary.DataBind();

}
else
{
    myReader1.Close();
    //myConnection.Close();
    //Label2.Text = "No Records Exist";
}
myReader1.Close();

Upvotes: 0

Views: 1687

Answers (3)

Brian
Brian

Reputation: 452

Don't call myReader1.Read(); if you're binding as a data source.

Upvotes: 1

Ronnie
Ronnie

Reputation: 670

Everything looks correct to me, except I don't think you should be calling

myReader1.Read();

before you bind to the GridView. I think if you remove that line it will fix your problem.

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68400

Remove myReader1.Read();, after ExecuteReader. That line causes the grid to start reading from the 2nd position.

Upvotes: 4

Related Questions