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


C# MySqlCommand.Dispose方法代码示例

本文整理汇总了C#中MySqlCommand.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlCommand.Dispose方法的具体用法?C# MySqlCommand.Dispose怎么用?C# MySqlCommand.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySqlCommand的用法示例。


在下文中一共展示了MySqlCommand.Dispose方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MySqlConnection

    public int fjöldi_rada()
    {
        MySqlConnection connection;

         string connectionString = "Server=10.0.105.33;Database=Leikur;Uid=first;Pwd=first;";

         connection = new MySqlConnection(connectionString);

         connection.Open();

         string query = @"SELECT * FROM spilari";
         MySqlCommand cmd = new MySqlCommand(query, connection);

         cmd.ExecuteNonQuery();

         MySqlDataReader queryCommandReader = cmd.ExecuteReader();

         DataTable dataTable = new DataTable();
         dataTable.Load(queryCommandReader);

         MySqlDataAdapter adapter = new MySqlDataAdapter();
         DataSet ds = new DataSet();
         adapter.SelectCommand = cmd;
         adapter.Fill(ds, "SQL Temp Table");
         adapter.Dispose();
         cmd.Dispose();

         return ds.Tables[0].Rows.Count;
    }
开发者ID:ellertsmari,项目名称:testrepo2,代码行数:29,代码来源:Form1.cs

示例2: ejecutarComando

 private int ejecutarComando(string sql)
 {
     MySqlCommand myCommand = new MySqlCommand(sql,this.myConnection);
         int afectadas = myCommand.ExecuteNonQuery();
         myCommand.Dispose();
         myCommand = null;
         return afectadas;
 }
开发者ID:BELKIEL,项目名称:practica-6,代码行数:8,代码来源:Program.cs

示例3: Buscarid

    public bool Buscarid( string id )
    {
        this.abrirConexion();
            MySqlCommand myCommand = new MySqlCommand(this.queryBuscar( id ),myConnection);
            MySqlDataReader myReader = myCommand.ExecuteReader();
            bool retorno = myReader.HasRows;

            myReader.Close();
            myReader = null;
           	 	myCommand.Dispose();
            myCommand = null;
            this.cerrarConexion();
            return retorno;
    }
开发者ID:BELKIEL,项目名称:practica-6,代码行数:14,代码来源:Program.cs

示例4: mostrarTodos

    public void mostrarTodos()
    {
        this.abrirConexion();
            MySqlCommand myCommand = new MySqlCommand(this.querySelect(),myConnection);
            MySqlDataReader myReader = myCommand.ExecuteReader();
            while (myReader.Read()){
                string id = myReader["id"].ToString();
                string codigo = myReader["codigo"].ToString();
                string nombre = myReader["nombre"].ToString();
                Console.WriteLine("ID: " + id +
                " Código: " + codigo +
                " Nombre: " + nombre);
            }

            myReader.Close();
            myReader = null;
           	 	myCommand.Dispose();
            myCommand = null;
            this.cerrarConexion();
    }
开发者ID:BELKIEL,项目名称:practica-6,代码行数:20,代码来源:Program.cs

示例5: select_from

    public string select_from()
    {
        MySqlConnection connection;

         string connectionString = "Server=10.0.105.33;Database=Leikur;Uid=first;Pwd=first;";

         connection = new MySqlConnection(connectionString);

         connection.Open();

         string query = @"SELECT * FROM spilari";
         MySqlCommand cmd = new MySqlCommand(query, connection);

         cmd.ExecuteNonQuery();

         MySqlDataReader queryCommandReader = cmd.ExecuteReader();

         DataTable dataTable = new DataTable();
         dataTable.Load(queryCommandReader);

         MySqlDataAdapter adapter = new MySqlDataAdapter();
         DataSet ds = new DataSet();
         adapter.SelectCommand = cmd;
         adapter.Fill(ds, "SQL Temp Table");
         adapter.Dispose();
         cmd.Dispose();

         String rowText = string.Empty;
         int topRows = ds.Tables[0].Rows.Count;
         for (int i = 0; i < topRows; i++)
         {

             foreach (DataColumn column in dataTable.Columns)
             {
                 rowText += dataTable.Rows[i][column.ColumnName] + "|";
             }
             rowText = rowText + "-";
         }

         connection.Close();
         return rowText;
    }
开发者ID:ellertsmari,项目名称:testrepo2,代码行数:42,代码来源:Form1.cs

示例6: ExecuteSqlTran

 /// <summary>
 /// 执行多条SQL语句,实现数据库事务。
 /// </summary>
 /// <param name="SQLStringList">多条SQL语句</param>		
 public static void ExecuteSqlTran(ArrayList SQLStringList)
 {
     using (MySqlConnection conn = new MySqlConnection(connectionString))
     {
         conn.Open();
         MySqlCommand cmd = new MySqlCommand();
         cmd.Connection = conn;
         MySqlTransaction tx = conn.BeginTransaction();
         cmd.Transaction = tx;
         try
         {
             for (int n = 0; n < SQLStringList.Count; n++)
             {
                 string strsql = SQLStringList[n].ToString();
                 if (strsql.Trim().Length > 1)
                 {
                     cmd.CommandText = strsql;
                     cmd.ExecuteNonQuery();
                 }
             }
             tx.Commit();
         }
         catch (MySqlException E)
         {
             tx.Rollback();
             throw new Exception(E.Message);
         }
         finally
         {
             cmd.Dispose();
             conn.Close();
         }
     }
 }
开发者ID:zuifengke,项目名称:windy-dotnet,代码行数:38,代码来源:MySqlHelper.cs

示例7: Query2

 /// <summary>
 /// 执行查询语句,返回DataSet
 /// </summary>
 /// <param name="SQLString">查询语句</param>
 /// <returns>DataSet</returns>
 public DataSet Query2(string SQLString, params  Object[] cmdParms)
 {
     using (MySqlConnection connection = new MySqlConnection(connectionString))
     {
         MySqlCommand cmd = new MySqlCommand();
         PrepareCommand(cmd, connection, null, SQLString, cmdParms);
         using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
         {
             DataSet ds = new DataSet();
             try
             {
                 da.Fill(ds, "ds");
                 cmd.Parameters.Clear();
             }
             catch (MySqlException ex)
             {
                 throw new Exception(ex.Message);
             }
             finally
             {
                 cmd.Dispose();
                 connection.Close();
             }
             return ds;
         }
     }
 }
开发者ID:zuifengke,项目名称:windy-dotnet,代码行数:32,代码来源:MySqlHelper.cs

示例8: ExecuteSqlByTime

 /// <summary>
 /// 执行SQL语句,设置命令的执行等待时间
 /// </summary>
 /// <param name="SQLString"></param>
 /// <param name="Times"></param>
 /// <returns></returns>
 public static int ExecuteSqlByTime(string SQLString, int Times)
 {
     using (MySqlConnection connection = new MySqlConnection(connectionString))
     {
         using (MySqlCommand cmd = new MySqlCommand(SQLString, connection))
         {
             try
             {
                 connection.Open();
                 cmd.CommandTimeout = Times;
                 int rows = cmd.ExecuteNonQuery();
                 return rows;
             }
             catch (MySqlException E)
             {
                 throw new Exception(E.Message);
             }
             finally
             {
                 cmd.Dispose();
                 connection.Close();
             }
         }
     }
 }
开发者ID:zuifengke,项目名称:windy-dotnet,代码行数:31,代码来源:MySqlHelper.cs

示例9: GetSingle

 /// <summary>
 /// 执行一条计算查询结果语句,返回查询结果(object)。
 /// </summary>
 /// <param name="SQLString">计算查询结果语句</param>
 /// <returns>查询结果(object)</returns>
 public static object GetSingle(string SQLString, params  Object[] cmdParms)
 {
     using (MySqlConnection connection = new MySqlConnection(connectionString))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             try
             {
                 PrepareCommand(cmd, connection, null, SQLString, cmdParms);
                 object obj = cmd.ExecuteScalar();
                 cmd.Parameters.Clear();
                 if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
                 {
                     return null;
                 }
                 else
                 {
                     return obj;
                 }
             }
             catch (MySqlException e)
             {
                 throw new Exception(e.Message);
             }
             finally
             {
                 cmd.Dispose();
                 connection.Close();
             }
         }
     }
 }
开发者ID:zuifengke,项目名称:windy-dotnet,代码行数:37,代码来源:MySqlHelper.cs

示例10: ExecuteSql

 /// <summary>
 /// 执行SQL语句,返回影响的记录数
 /// </summary>
 /// <param name="SQLString">SQL语句</param>
 /// <returns>影响的记录数</returns>
 public static int ExecuteSql(string SQLString, params  Object[] cmdParms)
 {
     using (MySqlConnection connection = new MySqlConnection(connectionString))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             try
             {
                 PrepareCommand(cmd, connection, null, SQLString, cmdParms);
                 int rows = cmd.ExecuteNonQuery();
                 cmd.Parameters.Clear();
                 return rows;
             }
             catch (MySqlException E)
             {
                 throw new Exception(E.Message);
             }
             finally
             {
                 cmd.Dispose();
                 connection.Close();
             }
         }
     }
 }
开发者ID:zuifengke,项目名称:windy-dotnet,代码行数:30,代码来源:MySqlHelper.cs

示例11: ExecuteSqlInsertImg

 /// <summary>
 /// 向数据库里插入图像格式的字段(和上面情况类似的另一种实例)
 /// </summary>
 /// <param name="strSQL">SQL语句</param>
 /// <param name="fs">图像字节,数据库的字段类型为image的情况</param>
 /// <returns>影响的记录数</returns>
 public static int ExecuteSqlInsertImg(string strSQL, byte[] fs)
 {
     using (MySqlConnection connection = new MySqlConnection(connectionString))
     {
         MySqlCommand cmd = new MySqlCommand(strSQL, connection);
         MySqlParameter myParameter = new MySqlParameter("?fs", MySqlDbType.Blob);
         myParameter.Value = fs;
         cmd.Parameters.Add(myParameter);
         try
         {
             connection.Open();
             int rows = cmd.ExecuteNonQuery();
             return rows;
         }
         catch (MySqlException E)
         {
             throw new Exception(E.Message);
         }
         finally
         {
             cmd.Dispose();
             connection.Close();
         }
     }
 }
开发者ID:zuifengke,项目名称:windy-dotnet,代码行数:31,代码来源:MySqlHelper.cs

示例12: ExecuteSqlGet

 /// <summary>
 /// 执行带一个存储过程参数的的SQL语句。
 /// </summary>
 /// <param name="SQLString">SQL语句</param>
 /// <param name="content">参数内容,比如一个字段是格式复杂的文章,有特殊符号,可以通过这个方式添加</param>
 /// <returns>影响的记录数</returns>
 public static object ExecuteSqlGet(string SQLString, string content)
 {
     using (MySqlConnection connection = new MySqlConnection(connectionString))
     {
         MySqlCommand cmd = new MySqlCommand(SQLString, connection);
         MySqlParameter myParameter = new MySqlParameter("?content", MySqlDbType.VarChar);
         myParameter.Value = content;
         cmd.Parameters.Add(myParameter);
         try
         {
             connection.Open();
             object obj = cmd.ExecuteScalar();
             if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
             {
                 return null;
             }
             else
             {
                 return obj;
             }
         }
         catch (MySqlException E)
         {
             throw new Exception(E.Message);
         }
         finally
         {
             cmd.Dispose();
             connection.Close();
         }
     }
 }
开发者ID:zuifengke,项目名称:windy-dotnet,代码行数:38,代码来源:MySqlHelper.cs


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