-
ADO.Net step by step
howdy~
i used to code with ASP and now want to touch something on ASP.Net, fist i wonder how can i make connections with ADO.Net, i checked some tutos and find there must be 3 or 4 steps for achieve this. for i know first is to import System.Data.SqlClient class and build an instance of it, but get confused next steps ? anyone can share example code here plz ?
-
PHP Code:
SqlConnection connection;
try
{
connection = new SqlConnection();
connection.ConnectionString = "yourconnectstring:databasevendordependent";
connection.Open();
}
catch( SqlException exception )
{
// error occurred, handle it here
}
The database connection string depends on the database server you have. I think the SqlConnection was meant to connect to an MS Sql Server. There are interfaces called IDbConnection and IDbCommand. Each database system can provide so-called data-providers for .NET to connect to their database system. Those implement the interfaces. For SQL Server its System.Data.SqlClient, for Oracle it's called ODP.NET and can be downloaded from Oracle or you can use the Microsoft drivers for Oracle. I don't know how they are called and I think you should use the drivers from the database vendor anyway.