示例#1
0
        private static List <string> ObtainTableNames()
        {
            List <string> oResponse = new List <string>();

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    SqlCommand command = new SqlCommand(SqlScriptGenerator.GenerateTableQueryScript(), connection);
                    command.CommandType    = CommandType.Text;
                    command.CommandTimeout = 60;

                    connection.Open();

                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        oResponse.Add(reader.GetString(0));
                    }
                    reader.Close();
                    connection.Close();
                    connection.Dispose();
                    command.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
            return(oResponse);
        }
示例#2
0
        private static void CreateBasicCrud()
        {
            List <string> tables = ObtainTableNames();

            foreach (string table in tables)
            {
                //Create procedure name.
                List <Column> columnInfo = ObtainTableInfo(table);

                string createStoredProcedure = SqlScriptGenerator.GenerateStoredProcedureScript(ScriptType.Create, "CREATE_" + SqlizeTable(table), table, columnInfo);
                ExecuteCommand(createStoredProcedure, 30);
                string readStoredProcedure = SqlScriptGenerator.GenerateStoredProcedureScript(ScriptType.Read, "VIEW_ALL_" + SqlizeTable(table), table, columnInfo);
                ExecuteCommand(readStoredProcedure, 30);
                string updateStoredProcedure = SqlScriptGenerator.GenerateStoredProcedureScript(ScriptType.Update, "UPDATE_" + SqlizeTable(table), table, columnInfo);
                ExecuteCommand(updateStoredProcedure, 30);
                string deleteStoredProcedure = SqlScriptGenerator.GenerateStoredProcedureScript(ScriptType.Delete, "DELETE_" + SqlizeTable(table), table, columnInfo);
                ExecuteCommand(deleteStoredProcedure, 30);
                string vbidStoredProcedure = SqlScriptGenerator.GenerateStoredProcedureScript(ScriptType.ViewById, "VIEW_" + SqlizeTable(table) + "_BY_ID", table, columnInfo);
                ExecuteCommand(vbidStoredProcedure, 30);
            }
        }
示例#3
0
        private static List <Column> ObtainTableInfo(string iTableName)
        {
            List <Column> oResponse = new List <Column>();

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    SqlCommand command = new SqlCommand(SqlScriptGenerator.GenerateDataTypeQueryScript(iTableName), connection);
                    command.CommandType    = CommandType.Text;
                    command.CommandTimeout = 60;

                    connection.Open();

                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        oResponse.Add(new Column
                        {
                            ColumnName   = reader.GetString(0),
                            DataType     = reader.GetString(1),
                            IsNullable   = reader.GetBoolean(2),
                            IsPrimaryKey = reader.GetBoolean(3)
                        });
                    }
                    reader.Close();
                    connection.Close();
                    connection.Dispose();
                    command.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
            return(oResponse);
        }