I am new to C# Windows Application coding and using Enterprise library.
I want to insert records into SQL Server 2008 database using Enterprise Library 4.1
I am getting confused between SQLCommand and DBCommand which one to use and when to use.
I am new to C# Windows Application coding and using Enterprise library.
I want to insert records into SQL Server 2008 database using Enterprise Library 4.1
I am getting confused between SQLCommand and DBCommand which one to use and when to use.
You don't need to use EntLib, just use old good ADO.NET:
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO table (column) VALUES (@param)";
command.Parameters.AddWithValue("@param", value);
connection.Open();
command.ExecuteNonQuery();
}
Here's the class signature on MSDN:
public sealed class SqlCommand : DbCommand, ICloneable
SqlCommand derives from DbCommand
DbCommand
(in the System.Data.Common namespace) is an abstract base class from which SqlCommand
, OleDbCommand
, OdbcCommand
. OracleCommand
, etc all are derived.
SQLcommand is a subclass of DBcommand. Use SQLcommand if you are connecting to SQL server
you can first try using SQLCommand - example here
and refer this if you want further information on SQL and DBCommand.