Mega Code Archive

 
Categories / C# / ADO Database
 

DataSet Read

using System; using System.Data;            // Use ADO.NET namespace using System.Data.SqlClient;  // Use SQL Server data provider namespace using System.Collections.Generic; using System.Text; class Program {     static void Main(string[] args) {         SqlConnection thisConnection = new SqlConnection(             @"Server=(local)\sqlexpress;Integrated Security=True;" +           "Database=northwind");         SqlDataAdapter thisAdapter = new SqlDataAdapter(              "SELECT CustomerID, ContactName FROM Customers", thisConnection);         DataSet thisDataSet = new DataSet();         thisAdapter.Fill(thisDataSet, "Customers");         foreach (DataRow theRow in thisDataSet.Tables["Customers"].Rows) {             Console.WriteLine(theRow["CustomerID"] + "\t" +                                                   theRow["ContactName"]);         }         thisConnection.Close();     } }