ADO.NET

<connectionStrings>
<add name="connString" connectionString="Data Source=FRED;Initial Catalog=AdventureWorks2017;Integrated Security=SSPI"/>
connectionStrings>
  static void ADO()
        {
            string connString = ConfigurationManager.ConnectionStrings["connString"].ToString();
            using (SqlConnection conn = new SqlConnection(connString))
            {
                if(conn.State!=ConnectionState.Open)
                {
                    conn.Open();
                }

                string selectSQL = $"select top(100) SalesOrderID,SalesOrderDetailID,CarrierTrackingNumber," +
                    "OrderQty,ProductID,SpecialOfferID,UnitPrice,UnitPriceDiscount,LineTotal,rowguid," +
                    "ModifiedDate from sales.SalesOrderDetail";
                using (SqlCommand cmd = new SqlCommand(selectSQL, conn))
                {
                    SqlDataReader dataReader = cmd.ExecuteReader();
                    while(dataReader.Read())
                    {
                        Console.WriteLine(dataReader[0] + "," + dataReader[1] + "," + dataReader[2] + "," + dataReader[3] + "," +
                            dataReader[4] + "," + dataReader[5] + "," + dataReader[6] + "," + dataReader[7] + "," + dataReader[8] + "," +
                            dataReader[9] + "," + dataReader[10]);
                    }
                }
            }
        }

 

你可能感兴趣的:(ADO.NET)