CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2001
    Posts
    80

    Looping through records (ADO .NET)

    I'm learning C# and I'm writing a little DB application.

    I've managed to get & display the first record, but how can I browse through the other records until EOF??? something like you could use in VB:

    While not rs.EOF()
    rs.Edit
    rs!["Column"] = "Test"
    rs.Update
    rs.MoveNext
    Wend

    any help or links to pages that would allow me to do the same as above would be great.

    Current code i have:
    ---------------------------------------------------------------------------
    myAdap = new OleDbDataAdapter ("SELECT * FROM PERSONEEL", conn);
    MyCommandBuilder = new OleDbCommandBuilder( myAdap );

    myAdap.Fill( ds , "Personeel");

    txtName.Text = ds.Tables["Personeel"].Rows[ 0 ]["Naam" ].ToString();
    txtGivenname.Text = ds.Tables["Personeel"].Rows[ 0 ]["voornaam" ].ToString();
    txtDOB.Text = ds.Tables["Personeel"].Rows[ 0 ]["GeboorteDatum"].ToString();
    txtAddress.Text = ds.Tables["Personeel"].Rows[ 0 ]["Adres" ].ToString();
    txtSalary.Text = ds.Tables["Personeel"].Rows[ 0 ]["Salaris" ].ToString();
    ---------------------------------------------------------------

  2. #2
    Join Date
    Mar 2004
    Posts
    48
    I prefer the OleDbDataReader, and I do it like this:
    Code:
    OleDbDataReader oReader;
    OleDbCommand oCmdSelect = new OleDbCommand( ... );
    oReader = oCmdSelect.ExecuteReader();
    while( oReader.Read() )
    {
        decimal myID = oReader.GetDecimal( 0 );
        ...
    }
    I've left out connection and SQL details for brevity.

  3. #3
    Join Date
    Oct 2001
    Posts
    80
    Thanks for your answer!

    But OleDBDataReader doesn't allow updates as far as I know.

  4. #4
    Join Date
    Mar 2004
    Posts
    48
    That's true, for inserts and updates I use the OleDbCommand object directly:
    Code:
    OleDbCommand oCmdUpdate = new OleDbCommand( ... );
    int nRowsUpdated = oCmdUpdate.ExecuteNonQuery();

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

Featured