开发者

sql data reader showing one record less than sql query output

开发者 https://www.devze.com 2023-02-25 15:35 出处:网络
i have made a simple stored开发者_高级运维 procedure to select all records where name will be like \'%search text%\'. the the stored procedure is returning correct results. But when i tried to show th

i have made a simple stored开发者_高级运维 procedure to select all records where name will be like '%search text%'. the the stored procedure is returning correct results. But when i tried to show these result set into gridview using sqldatareader, it populate one record less. Help Pls.


SqlConnection conn = new SqlConnection(connectionString);

SqlCommand command = new SqlCommand("select * from yourtable where yourcol like @parm" );
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@parm", searchText);

conn.Open();
command.Connection = conn;
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataSource = reader;
GridView1.DataBind();

if you're looping through the SqlDataReader, it's zero based.

0

精彩评论

暂无评论...
验证码 换一张
取 消