ErrMessage클래스 에러메시지_모듈
DB ConnectionString (myConnectionString)
public DataRow GetDataRow_Query(String sql)
{
DataTable table;
DataRow row;
DataSet ds;
SqlConnection connection;
SqlCommand command;
SqlDataAdapter ad;
table = new DataTable();
row = null;
connection = null;
try
{
connection = new SqlConnection();
connection.ConnectionString = myConnectionString;
connection.Open();
command = new SqlCommand();
command.Connection = connection;
command.CommandTimeout = 120;
command.CommandType = CommandType.Text;
command.CommandText = sql;
ds = new DataSet();
ad = new SqlDataAdapter();
ad.SelectCommand = command;
ad.Fill(ds);
if (ds.Tables.Count > 0)
{
table = ds.Tables[0];
if (table.Rows.Count > 0)
{
row = table.Rows[0];
}
}
}
catch (Exception e)
{
errMessage = new ErrMessage("GetDataRow_Query", e);
errMessage.ErrorMessageWrite();
}
finally
{
if (connection != null)
{
connection.Close();
}
}
return row;
}
public DataRow GetDataRow_Query_Parameter(String sql, SqlCommand executeCommand)
{
DataTable table;
DataRow row;
DataSet ds;
SqlDataAdapter ad;
SqlConnection connection;
table = new DataTable();
row = null;
connection = null;
try
{
connection = new SqlConnection();
connection.ConnectionString = myConnectionString;
connection.Open();
executeCommand.Connection = connection;
executeCommand.CommandTimeout = 120;
executeCommand.CommandType = CommandType.Text;
executeCommand.CommandText = sql;
ds = new DataSet();
ad = new SqlDataAdapter();
ad.SelectCommand = executeCommand;
ad.Fill(ds);
if (ds.Tables.Count > 0)
{
table = ds.Tables[0];
if (table.Rows.Count > 0)
{
row = table.Rows[0];
}
}
}
catch (Exception e)
{
errMessage = new ErrMessage("GetDataRow_Query_Parameter", e);
errMessage.ErrorMessageWrite();
}
finally
{
if (connection != null)
{
connection.Close();
}
}
return row;
}
public DataRow GetDataRow_Query_Parameter(String sql, Dictionary<String, Object> parameters)
{
DataTable table;
DataRow row;
DataSet ds;
SqlDataAdapter ad;
SqlConnection connection;
SqlCommand command;
table = new DataTable();
row = null;
connection = null;
try
{
connection = new SqlConnection();
connection.ConnectionString = myConnectionString;
connection.Open();
command = new SqlCommand();
command.Connection = connection;
command.CommandTimeout = 120;
command.CommandType = CommandType.Text;
command.CommandText = sql;
foreach (KeyValuePair<string, object> kvp in parameters)
{
command.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
ds = new DataSet();
ad = new SqlDataAdapter();
ad.SelectCommand = command;
ad.Fill(ds);
if (ds.Tables.Count > 0)
{
table = ds.Tables[0];
if (table.Rows.Count > 0)
{
row = table.Rows[0];
}
}
}
catch (Exception e)
{
errMessage = new ErrMessage("GetDataRow_Query_Parameter", e);
errMessage.ErrorMessageWrite();
}
finally
{
if (connection != null)
{
connection.Close();
}
}
return row;
}