using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
class Program
{
static void Main(string[] args)
{
SqlConnection thisConnection = new SqlConnection(
@"Data Source=.\SQLEXPRESS;" +
@"AttachDbFilename='NORTHWND.MDF';" +
@"Integrated Security=True;Connect Timeout=30;User Instance=true");
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();
}
}
|