Пример #1
0
        public List <SchemaRow> GetRoutineColumnSchema(string RoutineName, string RoutineType, bool IsProcedure, List <string> ParamList)
        {
            using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(this.ConnStr)) {
                conn.Open();

                using (MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand()) {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder("CALL `" + RoutineName + "` (");
                    for (int i = 0; i <= ParamList.Count - 1; i++)
                    {
                        sb.Append("NULL");
                        if (i < ParamList.Count - 1)
                        {
                            sb.Append(", ");
                        }
                    }
                    sb.Append(")");

                    cmd.Connection  = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sb.ToString();

                    DataTable dtSchema = new DataTable();
                    using (MySql.Data.MySqlClient.MySqlDataAdapter da = new MySql.Data.MySqlClient.MySqlDataAdapter(cmd)) {
                        da.FillSchema(dtSchema, SchemaType.Source);
                    }

                    conn.Close();

                    return(this.BuildColumns(RoutineName, RoutineType, IsProcedure, dtSchema));
                }
            }
        }
Пример #2
0
        public static DataSet ExecuteDataset(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);

                // Create the DataAdapter & DataSet
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    DataSet ds = new DataSet();

                    // Fill the DataSet using default values for DataTable names, etc
                    da.FillSchema(ds, SchemaType.Source);
                    da.Fill(ds);

                    // Detach the SqlParameters from the command object, so they can be used again
                    cmd.Parameters.Clear();

                    // Return the dataset
                    return(ds);
                }
            }
        }