当前位置: 首页>>代码示例>>C#>>正文


C# MySqlCommand.AddParameters方法代码示例

本文整理汇总了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");
         }
     }
 }
开发者ID:baizu2015,项目名称:MVCTest,代码行数:90,代码来源:MySQLHelper.cs


注:本文中的MySql.Data.MySqlClient.MySqlCommand.AddParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。