Beispiel #1
0
    /// <summary>
    /// Executes a single command against a MySQL database.
    /// </summary>
    /// <param name="connectionString">Settings to use for this command</param>
    /// <param name="commandText">Command text to use</param>
    /// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command</param>
    /// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns>
    public static MySqlDataReader ExecuteReader(string connectionString, string commandText, params MySqlParameter[] commandParameters)
    {
      //create & open a SqlConnection
      MySqlConnection cn = new MySqlConnection();
      cn.Open();

      //call the private overload that takes an internally owned connection in place of the connection string
      return ExecuteReader(cn, null, commandText, commandParameters, false);
    }
Beispiel #2
0
    /// <summary>
    /// Executes a single command against a MySQL database.  A new <see cref="MySqlConnection"/> is created
    /// using the <see cref="MySqlConnection.ConnectionString"/> given.
    /// </summary>
    /// <param name="connectionString"><see cref="MySqlConnection.ConnectionString"/> to use</param>
    /// <param name="commandText">SQL command to be executed</param>
    /// <param name="parms">Array of <see cref="MySqlParameter"/> objects to use with the command.</param>
    /// <returns></returns>
    public static int ExecuteNonQuery(string connectionString, string commandText, params MySqlParameter[] parms)
    {
      //create & open a SqlConnection, and dispose of it after we are done.
      using (MySqlConnection cn = new MySqlConnection())
      {
        cn.Open();

        //call the overload that takes a connection in place of the connection string
        return ExecuteNonQuery(cn, commandText, parms);
      }
    }
Beispiel #3
0
 /// <summary>
 /// Updates the given table with data from the given <see cref="DataSet"/>
 /// </summary>
 /// <param name="connectionString">Settings to use for the update</param>
 /// <param name="commandText">Command text to use for the update</param>
 /// <param name="ds"><see cref="DataSet"/> containing the new data to use in the update</param>
 /// <param name="tablename">Tablename in the dataset to update</param>
 public static void UpdateDataSet(string connectionString, string commandText, DataSet ds, string tablename)
 {
   MySqlConnection cn = new MySqlConnection();
   cn.Open();
   MySqlDataAdapter da = new MySqlDataAdapter(commandText, cn);
   MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
   cb.ToString();
   da.Update(ds, tablename);
   cn.Close();
 }