本文整理汇总了C#中System.Data.SqlClient.SqlParameter.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# SqlParameter.ToList方法的具体用法?C# SqlParameter.ToList怎么用?C# SqlParameter.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlParameter
的用法示例。
在下文中一共展示了SqlParameter.ToList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetData
public static DataTable GetData(DataBase dataBaseType, CommandType commandType, string query, SqlParameter[] parameters = null)
{
SqlConnection conn = new SqlConnection(GetConnectionStaring(dataBaseType));
SqlCommand cmd = conn.CreateCommand();
SqlDataReader reader = null;
try
{
cmd.CommandType = commandType;
cmd.CommandText = query;
if (parameters != null)
parameters.ToList().ForEach(s =>
{
cmd.Parameters.Add(s);
});
DataTable dt = new DataTable();
conn.Open();
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
dt.Load(reader);
return dt;
}
catch (Exception ex)
{
throw;
}
finally
{
if (reader != null && !reader.IsClosed)
{
reader.Close();
}
if (cmd != null)
{
if (cmd.Parameters != null)
{
cmd.Parameters.Clear();
}
cmd.Dispose();
}
if (conn != null && conn.State == ConnectionState.Open)
{
conn.Close();
conn.Dispose();
}
}
}
示例2: GetValuesList
private List<string> GetValuesList(SqlParameter[] args)
{
var values = new List<string>();
args.ToList().ForEach(arg =>
{
var param = arg;
var value = param.Value;
if (value == null)
value = "NULL";
else if (value.GetType() != typeof(int))
value = "'" + value + "'";
values.Add(Left(value.ToString()));
});
return values;
}
示例3: StoreData_ExecuteNonQuery
public static int StoreData_ExecuteNonQuery(DataBase dataBaseType, CommandType commandType, string query, SqlParameter[] parameters = null, List<TVParameter> TVParameters = null)
{
SqlConnection conn = new SqlConnection(GetConnectionStaring(dataBaseType));
SqlCommand cmd = conn.CreateCommand();
try
{
cmd.CommandType = commandType;
cmd.CommandText = query;
if (parameters != null)
parameters.ToList().ForEach(s =>
{
cmd.Parameters.Add(s);
});
if (TVParameters != null)
TVParameters.ToList().ForEach(s =>
{
SqlParameter tvpParam = cmd.Parameters.AddWithValue(s.ParameterName, s.ParameterValue);
tvpParam.SqlDbType = s.SqlDbType;
tvpParam.TypeName = s.ParameterTypeName;
});
conn.Open();
return cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw;
}
finally
{
if (cmd != null)
{
if (cmd.Parameters != null)
{
cmd.Parameters.Clear();
}
cmd.Dispose();
}
if (conn != null && conn.State == ConnectionState.Open)
{
conn.Close();
conn.Dispose();
}
}
}