Results 1 to 3 of 3

Thread: Reader get one row at a time

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    270

    Reader get one row at a time

    I have bit coneputal problem .

    The SqlDataReader can only retrieve one row at a time from the data source and in order for it to get the next record, it has to maintain its connection to the data source..

    string sSQL = "SELECT * FROM Products";
    string sConnString =
    "Server=(local);Database=Northwind;Integrated Security=SSPI;";
    using (SqlConnection oCn = new SqlConnection(sConnString))
    {
    SqlCommand oSelCmd = new SqlCommand(sSQL, oCn);
    oSelCmd.CommandType = CommandType.Text;
    oCn.Open();
    SqlDataReader oDr = oSelCmd.ExecuteReader();
    DataGrid1.DataSource = oDr;
    DataGrid1.DataBind();
    }

    if it get one row at a time then how it binds the data to grid if it contain one record at a time

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Reader get one row at a time

    Thread moved from CodeBank forum (which is for you to post your code examples, not questions)

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Reader get one row at a time

    The DataGrid just goes through each row in the datareader, and in each row, reads each column. It stores it in its own datasource and dynamically generates the corresponding rows and columns. It doesn't go 'back' when reading from the datareader. Internally, the databinding code may understand the type of the datareader and appropriately perform the 'while dr.read()'.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width