本文整理汇总了C#中MySql.Data.MySqlClient.MySqlCommand.AddParameters方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlCommand.AddParameters方法的具体用法?C# MySqlCommand.AddParameters怎么用?C# MySqlCommand.AddParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlCommand
的用法示例。
在下文中一共展示了MySqlCommand.AddParameters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuMySQLRDataTable
/// <summary>
/// Execute SQL Script and get the DataTable
/// </summary>
/// <param name="strSQL">SQL Script</param>
/// <param name="parms">
/// The parameters for the SQL command. Each "parameter" should be given as a pair of actual C# parameter where the first one
/// should be the SQL variable name and the second one is the value for such variable.
/// </param>
/// <returns>DataTable</returns>
public static DataSet ExecuMySQLRDataTable(string strSQL, string DBSource, params object[] parms)
{
if (string.IsNullOrEmpty(DBSource))
{
if (log.IsErrorEnabled)
{
log.Error("The DB Source of Dars can't been found!");
}
return null;
}
if (string.IsNullOrEmpty(strSQL))
{
if (log.IsWarnEnabled)
{
log.Warn("The SQL Statement of Dars is error");
}
return null;
}
int stage = 0;
try
{
using (var conn = new MySqlConnection(DBSource))
{
stage = 1;
conn.Open();
stage = 2;
using (var cmd = new MySqlCommand(strSQL, conn))
{
stage = 3;
using (var adapter = new MySqlDataAdapter(cmd.AddParameters(parms)))
{
stage = 4;
var dataTable = new DataSet();
adapter.Fill(dataTable,"ds");
return dataTable;
}
}
}
}
catch (Exception e)
{
switch (stage)
{
case 0:
if (log.IsWarnEnabled)
{
log.Warn("Init the connection of Dars is error", e);
return null;
}
throw new Exception(e.Message.ToString());
case 1:
if (log.IsWarnEnabled)
{
log.Warn("Open the connection of Dars is error", e);
return null;
}
throw new Exception(e.Message.ToString());
case 2:
if (log.IsWarnEnabled)
{
log.Warn("Exeception for executing SQL statement of Dars", e);
return null;
}
throw new Exception(e.Message.ToString());
case 3:
if (log.IsWarnEnabled)
{
log.Warn("Exeception for creating SQL data adapter of Dars", e);
}
throw new Exception(e.Message.ToString());
case 4:
if (log.IsWarnEnabled)
{
log.Warn("Exeception for filling data table of Dars", e);
}
throw new Exception(e.Message.ToString());
default:
throw new ApplicationException("Bad program flow");
}
}
}