本文整理汇总了C#中MySql.Data.MySqlClient.MySqlDataAdapter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlDataAdapter.Close方法的具体用法?C# MySqlDataAdapter.Close怎么用?C# MySqlDataAdapter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlDataAdapter
的用法示例。
在下文中一共展示了MySqlDataAdapter.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getAllEmployee
public List<Employee> getAllEmployee(Employee emp, String sortColumn,Boolean asc,Boolean exactFilter)
{
List<Employee> result = new List<Employee>();
MySqlTransaction tr = null;
MySqlDataAdapter rdr = null;
String sql = "SELECT * FROM EMPLOYEE WHERE 1=1 ";
Dictionary<String, String> paramDic = new Dictionary<String, String>();
if(emp != null)
{
String strFilter = emp.getStrFilter();
if (!String.IsNullOrWhiteSpace(strFilter))
{
if (exactFilter)
{
sql += " AND E_NAME = @NAME ";
paramDic.Add("@NAME",strFilter);
}
else
{
sql += " AND E_NAME LIKE '% @NAME %' ";
paramDic.Add("@NAME",strFilter);
}
}
}
if(sortColumn != null)
{
String sort = (asc == true? "ASC":"DSC");
sql += " ORDER BY @COLUMN @SORT ";
paramDic.Add("@COLUMN",sortColumn);
paramDic.Add("@SORT", sort);
}
try
{
conn = getConnection();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.Transaction = tr;
cmd.CommandText = sql;
foreach (KeyValuePair<String, String> pair in paramDic)
{
cmd.Parameters.AddWithValue(pair.Key, pair.Value);
}
rdr = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
rdr.Fill(dt);
tr.Commit();
}
catch (Exception ex)
{
tr.Rollback();
}
finally
{
if(rdr != null)
{
rdr.Close();
}
DBUtil.CloseConnection(conn);
}
return result;
}