本文整理汇总了C#中System.Data.SqlClient.SqlCommand.SQLCommandTextDump方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.SQLCommandTextDump方法的具体用法?C# SqlCommand.SQLCommandTextDump怎么用?C# SqlCommand.SQLCommandTextDump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.SQLCommandTextDump方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteSQLRetDS
/// <summary>
/// Выполить SQL запрос и вернуть DataSet
/// </summary>
/// <param name="_sql">SQL запрос</param>
/// <returns>Исходящий DataSet</returns>
public static DataSet ExecuteSQLRetDS(string _sql)
{
string InitString = "";
if (Config.DBAuth.Login == null || Config.DBAuth.Login=="")
InitString = "Data Source=" + Config.DBAuth.URL + ";Initial Catalog=" + Config.DBAuth.AuthToken + ";Trusted_Connection=true;Connect Timeout = 120;";
else
InitString = "Data Source=" + Config.DBAuth.URL + ";Initial Catalog=" + Config.DBAuth.AuthToken + ";User Id=" + Config.DBAuth.Login + ";Password=" + Config.DBAuth.Password + ";Connect Timeout = 120;";
DataSet retval = new DataSet();
using (var con = new SqlConnection(InitString))
{
using (var command = new SqlCommand(_sql, con) { CommandType = CommandType.Text })
{
try {
con.Open();
using (var da = new SqlDataAdapter(command))
{
da.Fill(retval);
}
con.Close();
}
catch (Exception _ex)
{
TLogger.Add("TMSSQLConnector. EXCEPTION: " + _ex.Message + " SQL: " + command.SQLCommandTextDump(), TLogger.MSGType.eEmail);
throw _ex;
}
}
}
return retval;
}
示例2: ExecuteProcRetString
/// <summary>
/// Выполнить SQL процедуру и вернуть первую строку
/// </summary>
/// <param name="_procname">Имя процедуры</param>
/// <param name="_param">Массив параметров</param>
/// <returns>Результат в виде строки</returns>
public static string ExecuteProcRetString(string _procname, List<SqlParameter> _param = null)
{
string InitString = "";
if (Config.DBAuth.Login == null || Config.DBAuth.Login == "")
InitString = "Data Source=" + Config.DBAuth.URL + ";Initial Catalog=" + Config.DBAuth.AuthToken + ";Trusted_Connection=true;Connect Timeout = 120;";
else
InitString = "Data Source=" + Config.DBAuth.URL + ";Initial Catalog=" + Config.DBAuth.AuthToken + ";User Id=" + Config.DBAuth.Login + ";Password=" + Config.DBAuth.Password + ";Connect Timeout = 120;";
string retval = "";
using (var con = new SqlConnection(InitString))
{
using (var command = new SqlCommand(_procname, con) { CommandType = CommandType.StoredProcedure })
{
if (_param != null)
{
foreach (var val in _param)
{
command.Parameters.Add(val);
}
}
try
{
con.Open();
object ret = command.ExecuteScalar();
if (ret != null && ret != DBNull.Value)
retval = ret.ToString();
con.Close();
}
catch (Exception _ex)
{
TLogger.Add("TMSSQLConnector. EXCEPTION: " + _ex.Message + " SQL: " + command.SQLCommandTextDump(), TLogger.MSGType.eEmail);
throw _ex;
}
}
}
return retval;
}
示例3: ExecuteSQLCommand
public static int ExecuteSQLCommand(SqlCommand _cmd)
{
string InitString = "";
if (Config.DBAuth.Login == null || Config.DBAuth.Login == "")
InitString = "Data Source=" + Config.DBAuth.URL + ";Initial Catalog=" + Config.DBAuth.AuthToken + ";Trusted_Connection=true;Connect Timeout = 120;";
else
InitString = "Data Source=" + Config.DBAuth.URL + ";Initial Catalog=" + Config.DBAuth.AuthToken + ";User Id=" + Config.DBAuth.Login + ";Password=" + Config.DBAuth.Password + ";Connect Timeout = 120;";
int retval = -1;
using (var con = new SqlConnection(InitString))
{
_cmd.Connection = con;
try {
con.Open();
retval = int.Parse(_cmd.ExecuteScalar().ToString());
con.Close();
}
catch (Exception _ex)
{
TLogger.Add("TMSSQLConnector. EXCEPTION: " + _ex.Message + " SQL: " + _cmd.SQLCommandTextDump(), TLogger.MSGType.eEmail);
throw _ex;
}
}
return retval;
}
示例4: ExecuteProcRetDS
/// <summary>
/// Выполнить SQL процедуру и вернуть DataSet
/// </summary>
/// <param name="_procname">Имя процедуры</param>
/// <param name="_param">Массив параметров</param>
/// <returns>Исходящий DataSet</returns>
public static DataSet ExecuteProcRetDS(string _procname, List<SqlParameter> _param = null)
{
string InitString = "";
if (Config.DBAuth.Login == null || Config.DBAuth.Login == "")
InitString = "Data Source=" + Config.DBAuth.URL + ";Initial Catalog=" + Config.DBAuth.AuthToken + ";Trusted_Connection=true;Connect Timeout = 120;";
else
InitString = "Data Source=" + Config.DBAuth.URL + ";Initial Catalog=" + Config.DBAuth.AuthToken + ";User Id=" + Config.DBAuth.Login + ";Password=" + Config.DBAuth.Password + ";Connect Timeout = 120;";
DataSet retval = new DataSet();
using (var con = new SqlConnection(InitString))
{
using (var command = new SqlCommand(_procname, con) {CommandType = CommandType.StoredProcedure})
{
if (_param!=null && _param.Count>0)
{
foreach (var val in _param)
{
command.Parameters.Add(val);
}
}
try {
con.Open();
using (var da = new SqlDataAdapter(command))
{
da.Fill(retval);
}
con.Close();
}
catch (Exception _ex)
{
TLogger.Add("TMSSQLConnector. EXCEPTION: " + _ex.Message + " SQL: " + command.SQLCommandTextDump(), TLogger.MSGType.eEmail);
throw _ex;
}
}
}
return retval;
}