locked
sloce RRS feed

  • Question

  • User-494664520 posted

    why in this case i cant use has row keyword? i want to search at bright table and do the if else statement.

     using (SqlConnection conStrstock8 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
                    {
                        string sqlupStockselect8 = "Select ProductID,ProductColorType,ProductSize WHERE ProductID=@pid AND ProductColorType=@protType AND ProductSize=@size";
                        using (SqlCommand cmdupstock8 = new SqlCommand(sqlupStockselect8, conStrstock8))
                        {
                            cmdupstock8.Parameters.AddWithValue("@pid", Id);
                            cmdupstock8.Parameters.AddWithValue("@protType", "Type8");
                            cmdupstock8.Parameters.AddWithValue("@size", " XS");
                            SqlDataReader myReader = cmdupstock8.ExecuteReader();
                            while (myReader.HasRows())
                            {
    
                            }
                        }

    Sunday, December 8, 2013 8:01 AM

Answers

  • User-933407369 posted

    hi kckcOng ,

    Straight off the bat I'd say readability. We all know that Read() will return False if there are no more rows to fetch, but Reader.HasRows is much more telling as to what it does than Read().

    i would suggest you read the follow link for more information:

    sqldatareader: Hasrows vs Read()

    http://forums.asp.net/t/1175522.aspx

    Hope it helps you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 10, 2013 4:20 AM

All replies

  • User-1716253493 posted
    If you use WHILE, i guess you don't need HASROW
    Sunday, December 8, 2013 10:23 AM
  • User-933407369 posted

    hi kckcOng ,

    Straight off the bat I'd say readability. We all know that Read() will return False if there are no more rows to fetch, but Reader.HasRows is much more telling as to what it does than Read().

    i would suggest you read the follow link for more information:

    sqldatareader: Hasrows vs Read()

    http://forums.asp.net/t/1175522.aspx

    Hope it helps you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 10, 2013 4:20 AM