I've looked into set up connection with database by using ado.net. I've been confused by DbConnection, SqlConnection, SqlCommand, DbCommand. Can someone tell me the difference?
I googled these terms, it seems like these DB prefix are the base class for these Sql prefix.
So when should we should these Sql prefix (SqlConnection) and when should we use DB prefix (DbConnection)?
Moreover, if I put the connection string in the App.config or Web.config, do I still need to use this kind of format for open and close the connection?
string connString = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;";
using (SqlConnection conn = new SqlConnection(connString))
{
}
Because after I've tried add the connection string in the App.config, it seems like I don't need to open and close connection anymore.
In addition, when to use SqlParameter? Can anyone give me an example?
Is that for passing the parameter from the stored procedure from database?
Is that more convenient to use the DataTable, DataSet or reader to pass the value?