here is a method that I wrote as part of a data library, that does an executenonquery it can handle transactions aswell.
You wil need to write a collection class that implements that IDataPrameterCollection interface to pass your sqlparameters to the method. or you can change the method. Hope it helps.
public int ExecuteNonQuery(string sql, CommandType commandType,
IDataParameterCollection parameters, SqlTransaction tran)
{
bool externalConnection = false;
IDbConnection connection = null;
try
{
if (tran != null)
{
connection = tran.Connection;
externalConnection = true;
}
else
{
connection = factory.CreateConnection()
connection.ConnectionStrin
}
IDbCommand command = factory.CreateCommand();
command.CommandType = commandType;
command.CommandText = sql;
if (parameters != null)
{
foreach (IDataParameter param in parameters)
{
command.Parameters.Add(par
}
}
command.Connection = connection;
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
if (tran != null)
command.Transaction = tran;
return command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToStr
}
finally
{
if (!externalConnection)
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Dispose();
}
}
}
Main Topics
Browse All Topics





by: guru_samiPosted on 2009-07-09 at 15:43:41ID: 24818938
looks you are not executing the command: uery();
l_objDBConnection.Open();
int result = l_objParamater.ExecuteNonQ
l_objDBConnection.Close();