namespace ConnectOleDbDataSource
{ class Program
{
static void Main(string[] args)
{
string oledbConnectString = "Provider=SQLOLEDB;Data Source=(local);" + "Initial Catalog=AdventureWorks;Integrated Security=SSPI";
string sqlSelect = "SELECT TOP 5 Title, FirstName, LastName " + "FROM Person.Contact"; // Create an ODBC Connection using
(OleDbConnection connection = new OleDbConnection(oledbConnectString)) { OleDbCommand command = new OleDbCommand(sqlSelect, connection);
// Execute the DataReader
connection.Open( );
OleDbDataReader reader = command.ExecuteReader( ); // Output the data from the DataReader to the console
while (reader.Read( ))
Console.WriteLine("{0} {1}", reader[0], reader[1]);
}
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey( );
}
}
}
string con = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["SchoolSys"].ToString();
add name="name" connectionString="Data Source=servername;Initial Catalog=dbname;UID=uid;PWD=pw" providerName="System.Data.SqlClient"
No comments:
Post a Comment