本文整理汇总了C#中CommandType.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# CommandType.Equals方法的具体用法?C# CommandType.Equals怎么用?C# CommandType.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandType
的用法示例。
在下文中一共展示了CommandType.Equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteNonQuery
//OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo
public void ExecuteNonQuery(CommandType commandType, string commandText, params object[] parameters)
{
SqlCommand cmdToExecute = new SqlCommand();
cmdToExecute.CommandText = commandText;
// Use base class' connection object
cmdToExecute.Connection = _mainConnection;
if (commandType.Equals(CommandType.StoredProcedure) && parameters != null && parameters.Length > 0)
{ //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters = GetSpParameterSet(cmdToExecute);
//assign the provided values to these parameters based on parameter order
AssignParameterValues(commandParameters, parameters);
}
try
{
if(_mainConnectionIsCreatedLocal)
{
// Open connection.
_mainConnection.Open();
}
else
{
if(_mainConnectionProvider.IsTransactionPending)
{
cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
}
}
cmdToExecute.ExecuteNonQuery();
// _errorCode = (Int32)cmdToExecute.Parameters["@iErrorCode"].Value;
//
// if(_errorCode != (int)LLBLError.AllOk)
// {
// // Throw error.
// throw new Exception("Stored Procedure 'sp_tblIPP_UpdateOne' reported the ErrorCode: " + _errorCode);
// }
return;
}
catch (Exception e)
{
throw new Exception(e.Message + " " + cmdToExecute.CommandText);
}
finally
{
if(_mainConnectionIsCreatedLocal)
{
// Close connection.
_mainConnection.Close();
}
cmdToExecute.Dispose();
}
}
示例2: ExecuteQuery
//OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo
public DataTable ExecuteQuery(CommandType commandType, string commandText, string tableName, params object[] parameters)
{
SqlCommand cmdToExecute = new SqlCommand();
cmdToExecute.CommandText =commandText;
// Use base class' connection object
cmdToExecute.Connection = _mainConnection;
if (commandType.Equals(CommandType.TableDirect))
{
cmdToExecute.CommandText = "Select * From " + commandText;
cmdToExecute.CommandType = CommandType.Text;
}
else
{
cmdToExecute.CommandType = commandType;
}
if
(commandType.Equals(CommandType.StoredProcedure) && parameters != null && parameters.Length > 0)
{ //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters = GetSpParameterSet(cmdToExecute);
//assign the provided values to these parameters based on parameter order
AssignParameterValues(commandParameters, parameters);
}
if(_mainConnectionIsCreatedLocal)
{
// Open connection.
_mainConnection.Open();
}
else
{
if(_mainConnectionProvider.IsTransactionPending)
{
cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
}
}
SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
DataTable dt = new DataTable();
if (tableName != "")
dt.TableName = tableName;
try
{
adapter.Fill(dt);
return dt;
// _errorCode = (Int32)cmdToExecute.Parameters["@iErrorCode"].Value;
// if(_errorCode != (int)LLBLError.AllOk)
// {
// // Throw error.
// throw new Exception("Stored Procedure 'sp_tblIPP_SelectAll' reported the ErrorCode: " + _errorCode);
// }
}
catch (Exception e)
{
throw new Exception(e.Message + " " + cmdToExecute.CommandText);
}
finally
{
if(_mainConnectionIsCreatedLocal)
{
// Close connection.
_mainConnection.Close();
}
cmdToExecute.Dispose();
adapter.Dispose();
}
}
示例3: PrepareCommand
/// <summary>
/// 参数准备
/// </summary>
/// <param name="cmd"></param>
/// <param name="commandType"></param>
/// <param name="commandText"></param>
/// <param name="commandParameters"></param>
private void PrepareCommand(SqlCommand cmd, CommandType commandType, string commandText,
QueryParameterCollection commandParameters)
{
cmd.CommandType = commandType;
cmd.CommandText = commandText;
cmd.Connection = (SqlConnection)m_DbConnection;
cmd.Transaction = (SqlTransaction)trans;
if (commandText.IndexOf("''") >= 0)
{
var blankname = "@____blankchar_______";
commandText = commandText.Replace("''", blankname);
if (commandParameters == null) commandParameters = new QueryParameterCollection();
commandParameters.Add(blankname, "");
}
if ((commandParameters != null) && (commandParameters.Count > 0))
{
for (int i = 0; i < commandParameters.Count; i++)
{
commandParameters[i].InitRealParameter(DatabaseType.MSSQLServer);
cmd.Parameters.Add(commandParameters[i].RealParameter as SqlParameter);
}
}
Open();
//if (this.checkSQL)
//{
string notallow = string.Empty;
//所有的执行方式都检查参数,包括存储过程和SQL语句
//if (CheckSQL.CheckSQLText(commandParameters, out notallow) <= 0) //语句中有不允许的内容,如果是开发人员写的,请改写sql语句或写存储过程实现
//{
// Dev.Log.Loger.Error("sql语句中不允许出现:" + notallow);
// throw new Exception("数据格式不正确!!!");
//}
//}
//if (this.checkParms)
//{
//string notallow;
if (!commandType.Equals(CommandType.StoredProcedure) && CheckSQL.CheckSQLText(commandText, out notallow) <= 0)
//语句中有不允许的内容,如果是开发人员写的,请改写sql语句或写存储过程实现
{
Loger.Error("sql语句中不允许出现:" + notallow);
throw new Exception("数据格式不正确!!!注入字符" + notallow);
}
//}
//DBLog.AddLog("", commandType, commandText, commandParameters);
}