Answers for "connect to a database and loop over a recordset in C#"

C#
0

connect to a database and loop over a recordset in C#

using System.Data.OleDb;
...

using (OleDbConnection conn = new OleDbConnection())
{
    conn.ConnectionString = "Provider=sqloledb;Data Source=yourServername\\yourInstance;Initial Catalog=databaseName;Integrated Security=SSPI;";

    using (OleDbCommand cmd = new OleDbCommand())
    {
        conn.Open();
        cmd.Connection = conn;
        cmd.CommandText = "Select * from yourTable";

        using (OleDbDataReader dr = cmd.ExecuteReader())
        {
            while (dr.Read())
            {
                Console.WriteLine(dr["columnName"]);
            }
        }
    }
}
Posted by: Guest on July-28-2021

Code answers related to "connect to a database and loop over a recordset in C#"

C# Answers by Framework

Browse Popular Code Answers by Language